If you'd like to access the library then it can be a little complicated "looking" but it's possible. The normal way to make a library item appear on stage is just open the properties on any library element, go in properties and check off the "Export for ActionScript" while giving it a valid "class" name (letters, numbers, try to stick with that). For example if I named my library item in Export for ActionScript to "myClip1" then to display it I would: // make a new clip 'instance' of 'myClip1' from the Library var clip1:MovieClip = new myClip1(); // add it to the stage to be visible stage.addChild(clip1); Here's a shot including the properties panel. A few things to note. The drop-down in properties is set to make it a MovieClip as is the "Base Class" setting, so I must set the type in ActionScript (as you see highlighted) appropriately. In the code above the only extra thing is the stop() so it doesn't keep repeating the frame code. Also note that in the code I am only using the "Export for ActionScript" name, not the name of the library item. Run that and you'll see your clip appear. To grab something dynamically based on a variable like you're doing makes use of the getDefinitionByName() function so you can use variables to specify the name, like in the loop where it uses an index on the clips array and returns the string: clips. Since getDefinitionByName returns a class you typically convert it to the proper type as well. Like so: So your loop will look similar to this, assuming you have 3 clips in the library "clip1", "clip2", "clip99": import flash.utils.getDefinitionByName; stop() // keep track of the current clip var lastClip:int = 0; var currentClip:MovieClip; // filling an array with instance names on the timeline to choose between // add as many as you like var clips:Array = [ 'clip1', 'clip2', 'clip99' ];// assuming on the main stage // assign button handler, season name to taste changeClipbtn.addEventListener( MouseEvent.CLICK, changeClipHandler ); function changeClipHandler(e:MouseEvent):void { // assure clips contains something to assure no infinite loops if ( clips.length == 0 ) { return; }// no clips, do nothing // stop current clip currentClip.gotoAndStop(1); // only a single clip? play it again if ( clips.length == 1 ) { currentClip.gotoAndPlay(1); return; } // if we get here we at least have 2 clips // rand generate a number pointing to a spot in the array var nextClip:int = Math.floor( Math.random() * clips.length ); // if the generated number is the same as the last number, generate again while ( nextClip == lastClip ) { nextClip = Math.floor( Math.random() * clips.length ); } // track the new loading clip lastClip = nextClip; // remove existing clip from the stage stage.removeChild( currentClip ); // get a class reference to the new clip from the library var clipClass:Class = getDefinitionByName( clip[ nextClip ] ) as Class; // no class? do nothing if ( ! clipClass ) { return; } var currentClip = new clipClass() as MovieClip; // add to stage stage.addChild( currentClip ); // play clip currentClip.play(); } You can see the getDefinitionByName now. The class is retrieved from the library via the name you put in the array at the top (clip1, clip2, clip99 etc). If it finds a class via that name it is instantiated and added to the stage, and then told to play. It might look a little complicated but you should be able to tinker with it. It might give you an error (I did it off the top of my head, no Adobe Animate on this system at the moment) but I'm sure you can figure it out if it's just a typo. Season to taste.
... View more