Flash 需要延迟navigateToURL闪存AS3
我有一个MovieClip(称为“聊天”),当它被点击时播放,但当它播放完后,我需要它来导航URL。这是我得到的最接近的结果,但它不起作用:Flash 需要延迟navigateToURL闪存AS3,flash,actionscript-3,Flash,Actionscript 3,我有一个MovieClip(称为“聊天”),当它被点击时播放,但当它播放完后,我需要它来导航URL。这是我得到的最接近的结果,但它不起作用: var chatTimer:Timer = new Timer(1000); chats.addEventListener(MouseEvent.CLICK,startTimer); function startTimer(event:MouseEvent):void { chats.gotoAndPlay(2); chats.addEventListe
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"));
}
希望你能帮忙!
Steph似乎您希望在电影剪辑到达其时间轴的最后一帧后调用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);
}
}
希望这就是你想要的 感谢Marty,我收到了一条错误消息:“1046:Type未找到或不是编译时常量:”。关于var req:URLRequest(“);有什么想法吗?它是否说明找不到哪种类型?如果将此代码放入外部文件(类)中然后您需要导入以下内容:flash.display.MovieClip、flash.net.URLRequest、flash.net.navigateToURL、flash.events.Event.抱歉,对我来说有点晚了。错过了一个重要的部分!请尝试上面修改的代码:)我已经导入了它们并使用了您给我的代码,但是var-req:URLRequest(“stackoverflow.com”)仍然存在问题;lineI我忘了添加新的URLRequest(),而刚才的req:URLRequest(“”);非常适合我!