帧上的 Flash 触发 AS 代码
我是一名 Flex 开发人员,必须在 Flash 中进行一些编码,因此我对如何在时间线上放置操作的理解有些有限。
我正在尝试将此动作附加到我计划播放的电影的第一帧上。当我第一次播放电影时,代码按预期执行。但是,当我重新启动或倒回电影的第一帧时,代码不再执行。我不确定为什么会发生这种情况,因为似乎将动作脚本代码添加到框架中似乎非常简单。
import flash.utils.Timer;
import flash.net.URLLoader;
import flash.net.URLRequest;
var urlLoader:URLLoader;
var timer:Timer;
startAdPlay();
function startAdPlay():void
{
if( urlLoader == null ) {
urlLoader = new URLLoader();
}
urlLoader.load( new URLRequest( "http://localhost:20081/startadplay/15" ) );
timer = new Timer( (15 * 1000) );
timer.addEventListener(TimerEvent.TIMER, stopAdPlay );
timer.start();
}
function stopAdPlay(event:TimerEvent):void
{
urlLoader.load( new URLRequest( "http://localhost:20081/stopadplay" ) );
timer.stop();
stop();
}
I'm a Flex developer who had to do some coding in Flash, so my understanding of how putting an action on a time line is somewhat limited.
I'm trying to attach this action on the first frame of the movie that I'm planning play. When I play the movie for the first time, the code executes as expected. However, when I restart or rewind to the first frame of the movie, the code no longer executes. I'm not sure why this is happening, as it seemed added actionscript code to a frame seems pretty straight forward.
import flash.utils.Timer;
import flash.net.URLLoader;
import flash.net.URLRequest;
var urlLoader:URLLoader;
var timer:Timer;
startAdPlay();
function startAdPlay():void
{
if( urlLoader == null ) {
urlLoader = new URLLoader();
}
urlLoader.load( new URLRequest( "http://localhost:20081/startadplay/15" ) );
timer = new Timer( (15 * 1000) );
timer.addEventListener(TimerEvent.TIMER, stopAdPlay );
timer.start();
}
function stopAdPlay(event:TimerEvent):void
{
urlLoader.load( new URLRequest( "http://localhost:20081/stopadplay" ) );
timer.stop();
stop();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
鉴于您已经是一名 Flex 开发人员,因此习惯于在 Flash 之外的单独文件中编写代码,我建议您继续这样做,并在时间线上放置尽可能少的代码。纯粹主义者会建议在时间线上完全不添加任何代码,但我会将函数调用和dispatchEvent()命令放在时间线上。然而,被调用的实际函数是在单独的 .as 文件中定义的。
所以在你的情况下我只会把 startAdPlay();时间轴上的函数调用,并将实际的函数体放在一个单独的类中,该类链接到“属性”窗口中的 Flash 影片。这将使定义函数的时间和地点更加符合逻辑。
Given that you are already a Flex developer and thus used to writing your code in separate files outside Flash, I would recommend keep doing that and put as little code as possible on the timeline. Purists will recommend no code at all on the timeline, but I will put function calls and dispatchEvent() commands on the timeline. The actual function being called is defined in a separate .as file however.
So in your case I would just put the startAdPlay(); function call on the timeline, and put the actual function body in a separate class that is linked to the Flash movie in the Properties window. That'll make it more logical when and where the function is defined.
我想您在应用程序中重新启动电影时不会调用
startAdPlay()
I suppose you don't call
startAdPlay()
while restarting the movie in app