The following code shows you how to play a random movie clip when a button is pressed in Flash CS6 Actionscript 3 (AS3). To do this, I started with 4 movie clips that will be called at random. So that means that there is a main timeline and 4 movie clips, each with a button in them, that are placed on the main timeline.<\/p>\n
This code goes into the main time [CODE]<\/p>\n
stop();<\/p>\n
\/\/this code makes each movie clip invisible so its not being played. I put each movie clip on the main timeline you just cannot see them until they are called
\n\/\/easy1 easy2 easy3 and easy4 are instances. Be sure to give each of you movie clips an instance name.
\neasy1.visible = false;
\neasy2.visible = false;
\neasy3.visible = false;
\neasy4.visible = false;<\/p>\n
\/\/create an array with your instance names
\nvar storeArray:Array = [easy1, easy2, easy3, easy4];<\/p>\n
This is what the button does when pressed
\nfunction easyButton(pEvent:MouseEvent):void {
\n\/\/random clip from array. Note that these are all variables here no instances or anything.
\nvar myNumber = Math.floor(Math.random()*storeArray.length);
\ntrace(“myNumber “+myNumber);
\nvar activeCarton = storeArray[myNumber];
\n\/\/now we make the movie clip that was previously playing invisible and the new one replaces it
\neasy1.visible = false;
\neasy2.visible = false;
\neasy3.visible = false;
\neasy4.visible = false;
\nactiveCarton.visible = true;
\n}<\/p>\n
[ENDCODE] Now, in the timeline with my button, I put the following code. Keep in mind my button is in my movie clip. If yours was in the main timeline you would just delete that MovieClip(root). from the code:<\/p>\n
[CODE]<\/p>\n
\/\/easy1Button is the button instance name. easyButton is the function we created in the previous code.
\neasy1Button.addEventListener(MouseEvent.MOUSE_UP, MovieClip(root).easyButton);<\/p>\n
[ENDCODE]<\/p>\n","protected":false},"excerpt":{"rendered":"
The following code shows you how to play a random movie clip when a button is pressed in Flash CS6 Actionscript 3 (AS3). To do this, I started with 4 movie clips that will be called at random. So that means that there is a main timeline and 4 movie clips, each with a button […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[21],"tags":[279,62,280],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/posts\/1284"}],"collection":[{"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1284"}],"version-history":[{"count":2,"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/posts\/1284\/revisions"}],"predecessor-version":[{"id":1286,"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/posts\/1284\/revisions\/1286"}],"wp:attachment":[{"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raypastore.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}