我有一个MovieClip(称为“聊天”),它在点击时播放,但是当它完成播放时我需要它来导航。这和我一样接近,但它不起作用:
var chatTimer:Timer = new Timer(1000);
chats.addEventListener(MouseEvent.CLICK,startTimer);
function startTimer(event:MouseEvent):void {
chats.gotoAndPlay(2);
chats.addEventListener(TimerEvent.TIMER_COMPLETE,urlAction);
function urlAction(){
chatTimer.stop();
navigateToURL(new URLRequest("http://www.stackoverflow.com"));
}
希望你能帮忙! 斯蒂芬
答案 0 :(得分:1)
一旦动画片段到达其时间轴中的最后一帧,您似乎想要调用navigateToURL。如果您使用totalFrames和currentFrame属性,这会更容易,如下所示:
chats.addEventListener(MouseEvent.CLICK, begin);
/**
* Begins the playing of chats
*/
function begin(e:MouseEvent):void
{
// only runs if the movieclip is on frame 1
// (can't click it multiple times)
if(chats.currentFrame == 1)
{
chats.gotoAndPlay(2);
chats.addEventListener(Event.ENTER_FRAME, _handleChats);
}
}
function _handleChats(e:Event):void
{
var m:MovieClip = MovieClip(e.target);
if(m.currentFrame == m.totalFrames)
{
m.stop();
var req:URLRequest = new URLRequest("http://stackoverflow.com/");
navigateToURL(req, "_blank");
m.removeEventListener(Event.ENTER_FRAME, _handleChats);
}
}
希望这就是你所追求的!