mardi 27 septembre 2016

what do i replace 'addFrameScript' with in object oriented as3?

im converting the code from this post to my main class. another class, which contains a clip, is passed through an array and played with playScene()...

public class Main extends MovieClip
    {
        private var myInterface:ui;
        private var playQueue:Array = new Array();

        public function Main()
        {
            trace("main is working");

            playQueue = [open_door];
            playScene();
        }

        public function playScene():void
        {
            //if there was an item previously playing (currentClip has a value), stop it and remove it.
            if(currentClip){
                currentClip.stop(); 
                currentClip.addFrameScript(currentClip.totalFrames-1, null); 
                currentClip.parent.removeChild(currentClip);
            }  

            //check if there's anything left to play
            if(playQueue.length < 1) {
                return;
            }

            trace(playQueue);
            trace(playQueue.length);

            var nextItem:* = playQueue.shift();

            if(nextItem is Class){
                //if it's a class, provide an instance of it
                var currentClip = new nextItem();
            }else{
                var currentClip = MovieClip(nextItem);
            }


            addChild(currentClip);
            currentClip.x = 412.4;
            currentClip.y = 244.5;
            currentClip.gotoAndPlay(1);

            //add a command on the last frame of the movie clip to play the next item in the queue
            currentClip.addFrameScript(currentClip.totalFrames-1, playScene);
        }

    }
}

the clip plays fine, but it loops forever. when this function was timeline code, that .addFrameScript line added a piece of code to the last frame of the currentClip's timeline. now that currentClip stems from a class, the timeline code doesn't seem to apply anymore... what am I supposed to replace it with? how does OOP relate to object timelines?

Aucun commentaire:

Enregistrer un commentaire