Playing random movieClips onClick, then returning to start screen
hi- i'm new actionscript 3. project starts out plying 1 movie clip(startpage), onclick, moviecip startpage disappears , random movieclip(sc01-sc03) loads , plays. once each random movieclip plays, want remove stage , reload startpage. have random part figured out using array, can't figure out how remove random sc movieclip once loaded. tried using removechild, flash isn't recognizing have added , of sc movieclips childen. help!
my current code below:
package
{
import flash.display.movieclip;
import flash.events.mouseevent;
import flash.events.event;
public class main extends movieclip
{
var startpage:startpage;
var sc01:sc01;
var sc02:sc02;
var sc03:sc03;
private var _scenario:array;
public function main()
{
startpage = new startpage();
sc01 = new sc01();
sc02 = new sc02();
sc03 = new sc03();
_scenario = new array();
mc.addchild(startpage);
//add scenes array
_scenario[0] = sc01;
_scenario[1] = sc02;
_scenario[2] = sc03;
//add event listeners
startpage.boxbutton.addeventlistener(mouseevent.click,onboxbuttonclick);
startpage.addframescript(startpage.totalframes - 1, stoppagefunc);
sc01.addeventlistener(event.enter_frame, everyframe01);
sc02.addeventlistener(event.enter_frame, everyframe02);
sc03.addeventlistener(event.enter_frame, everyframe03);
//stop @ end of startpage timeline
function stoppagefunc()
{
startpage.stop();
}
function onboxbuttonclick(event:mouseevent):void
{
mc.removechild(startpage);
mc.addchild(_scenario[math.floor(math.random()*_scenario.length)]);
}
function everyframe01():void
{
if (sc01.currentframe == 50)
{
mc.removechild(sc01);
mc.addchild(startpage);
startpage.gotoandplay(1);
}
else
{sc01.play();
}
}
function everyframe02():void
{
if (sc02.currentframe == 50)
{
mc.removechild(sc02);
mc.addchild(startpage);
startpage.gotoandplay(1);
}
else
{sc02.play();
}
}
function everyframe03():void
{
if (sc03.currentframe == 50)
{
mc.removechild(sc03);
mc.addchild(startpage);
startpage.gotoandplay(1);
}
else
{sc03.play();
}
}
//go startpage when scenario done
}
}
}
use:
package
{
import flash.display.movieclip;
import flash.events.mouseevent;
import flash.events.event;
public class main extends movieclip
{
var startpage:startpage;
private var _scenario:array;
public function main()
{
startpage = new startpage();
_scenario = new array();
mc.addchild(startpage);
//add scenes array
_scenario[0] = new sc01();
_scenario[1] = new sc02();
_scenario[2] = new sc03();
shuffle(_scenario);
//add event listeners
startpage.boxbutton.addeventlistener(mouseevent.click, onboxbuttonclick);
startpage.addframescript(startpage.totalframes - 1, stoppagefunc);
this.addeventlistener(event.enter_frame, everyframe;
//stop @ end of startpage timeline
function stoppagefunc()
{
startpage.stop();
}
function onboxbuttonclick(event:mouseevent):void
{
if(startpage.stage){
mc.removechild(startpage);
}
if(_scenario.length>0){
mc.addchild(_scenario[0]);
}
}
function everyframe():void
{
if(_scenario[0].currentframe==_scenario[0].totalframes){
mc.removechild(_scenario[0]);
_scenario.shift();
if(_scenario.length==0){
// startpage.gotoandplay(1); ???
mc.addchild(startpage);
}
}
}
function shuffle(a:array) {
var i:int;
var j:int;
var e:*;
var len:int = a.length;
(i = len-1; i>=0; i--) {
j=math.floor((i+1)*math.random());
e = a[i];
a[i] = a[j];
a[j] = e;
}
}
}
}
More discussions in ActionScript 3
adobe
Comments
Post a Comment