开发者

addFrameScript works in the Document Class, totally crashes on the timeline?

I have a question, I wrote the following test as a class:

package 
{
    import flash.display.MovieClip;
    import flash.display.FrameLabel;

    public class FrameLabels extends MovieClip
    {
        public function FrameLabels ()
        {
            var labelsList:Array = currentLabels;

            for (var i:int = 0; i < currentLabels.length; i++)
            {
                if (currentLabels[i].name == "monday")
                {
                    addFrameScript (currentLabels[i].frame-1, mondayHandler);
                }
                if (currentLabels[i].name == "tuesday")
                {
                    addFrameScript (currentLabels[i].frame-1, tuesdayHandler);
                }
                if (currentLabels[i].name == "wednesday")
                {
                    addFrameScript (currentLabels[i].frame-1, wednesdayHandler);
                }
            }
        }

        private function mondayHandler():void
        {
            trace("at monday at frame " + currentFrame);
        }
        private function tuesdayHandler():void
        {
            trace("at tuesday! at frame " + currentFrame);
        }
        private function wednesdayHandler():void
        {
            trace("at wednesday! at frame " + currentFrame);
        }




    }
}

I have frame labels: monday tuesday wednesday

This works great in a document class, however, 开发者_StackOverflow中文版when I put it on frame 1 of my timeline, it crashes Flash.

I have a stop action on the last frame so the playhead shouldn't be running the script over and over, is there any reason that this is crashing?

Timeline code:

var labelsList:Array = currentLabels;

for (var i:int = 0; i < currentLabels.length; i++)
{
    if (currentLabels[i].name == "monday")
    {
        addFrameScript (currentLabels[i].frame-1, mondayHandler);
    }
    if (currentLabels[i].name == "tuesday")
    {
        addFrameScript (currentLabels[i].frame-1, tuesdayHandler);
    }
    if (currentLabels[i].name == "wednesday")
    {
        addFrameScript (currentLabels[i].frame-1, wednesdayHandler);
    }
}


function mondayHandler ():void
{
    trace ("at monday at frame " + currentFrame);
}
function tuesdayHandler ():void
{
    trace ("at tuesday! at frame " + currentFrame);
}
function wednesdayHandler ():void
{
    trace ("at wednesday! at frame " + currentFrame);
}


Since SWF movies are designed for streaming, your code on frame 1 will execute as soon as frame 1 is loaded. If the rest of your movie has not finished loading, there is a good change that either the currentLabels property, or the frames you want to assign your handler scripts to are not yet set (null), which will cause the player to crash.

You have to make sure your script executes only when the SWF is fully loaded. Either export all content in the movie to frame 1 via the properties panel (so everything is loaded after frame 1 is loaded), or (better) create a preloader loop to check for bytesLoaded/bytesTotal.

This works in a document class, because the constructor is called after the document SWF has finished loading.


I took your as and tried to mimic your issue (using timeline code only)

What I found:

  • your code on layer 1 frame 1
  • monday on layer 2 frame 1, tuesday on layer 2 frame 11, wednesday on layer 2 frame 21
  • stop() on layer 1 frame 21

There were no errors for me, but I did find that the handler for wednesday ran before the stop() was triggered. I recommend putting a stop() after you handlers so the timline never plays int he first place. Let me know if there's anything else I can do to help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜