Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Play loop movies randomly but not completly randomly.

Explorer ,
Feb 09, 2013 Feb 09, 2013

Hello, I am using Adobe Flash CS6 and Action Script3.

Right now I am trying to play movie clips randomly. There are 5 loop movie clips.mcA,mcB,mcC,mcD and mcE.

mcA is 10 frames long, mcB is 10 frames, mcC is 10 frames, mcD is 20 frames and mcE is 10 frames.

I said randomly, but not completely randomly.I want to play them in this order.

mcA -mcB

        -mcB -mcB

mcC - mcD - mcE

                  - mcD - mcE

                  - mcD - mcD - mcE

So, first random pick is mcA or mcC. If mcA is selected, next choice is mcB or mcB-mcB.

If mcC is selected, mcD follows, and next, mcE or mcD-mcE or mcD - mcD -mcE.

I try using Math.random, frame label, visibility, linkage to play them randomly, but I can't make it work correctly.

Do you have any idea?  Please help me. Thank you in advance.

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 12, 2013 Feb 12, 2013

i used mcA for an array reference and you used mcA for a movieclip reference which caused that error:

// an array of arrays.  each element of a is allowable sequence of movieclips

var a:Array=[[mcA,mcB],[mcA,mcB,mcB],[mcC,mcD,mcE],[mcC,mcD,mcD,mcE],[mcC,mcD,mcD,mcD,mcE]];

// mc_A is a randomly chosen element of a.  ie, one of the allowable sequences of movieclips

var mc_A:Array=a[ Math.floor(Math.random()*a.length)]

// the movieclips in mcA will be played from the first until the last

var index:int=0;

...
Translate
Community Expert ,
Feb 09, 2013 Feb 09, 2013

just create an array of the allowable sequences and select one at random:

var a:Array=[[mcA,mcB],[mcA,mcB,mcB],[mcC,mcD,mcE],[mcC,mcD,mcD,mcE],[mcC,mcD,mcD,mcD,mcE]];

var mcA:Array = a[Math.floor(Math.random()*a.length)];

var index:int=0;

var mc:MovieClip;

playF();

function playF():void{

mc=mcA[index];

mc.addEventListener(Event.ENTER_FRAME,enterframeF);

}

function enterframeF(e:Event):void{

if(mc.currentFrame==mc.totalFrames){

mc.removeEventListener(Event.ENTER_FRAME,enterframeF);

index++;

if(index<mcA.length){

playF();

} else {

// all done.  do something?

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2013 Feb 11, 2013

Thank you.

Now I am trying to understand your script, but it's too hard.

var mcA:Array = a[Math.floor(Math.random()*a.length)];

Is it Array in Array? What this script does?

And  one more.

playF();

function playF():void{

mc=mcA[index];

mc.addEventListener(Event.ENTER_FRAME,enterframeF);

}

mc=mcA  means

MovieClip=mcA:Array = a[Math.floor(Math.random()*a.length)];

Is it right?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2013 Feb 11, 2013

:

// an array of arrays.  each element of a is allowable sequence of movieclips

var a:Array=[[mcA,mcB],[mcA,mcB,mcB],[mcC,mcD,mcE],[mcC,mcD,mcD,mcE],[mcC ,mcD,mcD,mcD,mcE]];

// mcA is a randomly chosen element of a.  ie, one of the allowable sequences of movieclips

var mcA:Array = a[Math.floor(Math.random()*a.length)];

// the movieclips in mcA will be played from the first until the last

var index:int=0;

var mc:MovieClip;

// playF starts the next movieclip in mcA playing (and as i'm typing this i realize i failed to add an mc.play() in playF)

playF();

function playF():void{

mc=mcA[index];

// start it playing

mc.play();

// if mc needs to be added to the stage or needs to be made visible etc, this is the place to do that

// add a loop to check when it finishes playing so we can start the next movieclip in mcA

mc.addEventListener(Event.ENTER_FRAME,enterframeF);

}

function enterframeF(e:Event):void{

// check if mc has completed play

if(mc.currentFrame==mc.totalFrames){

// if so, remove the listener

mc.removeEventListener(Event.ENTER_FRAME,enterframeF);

// if mc no longer needs to be on stage or no longer needs to be visible etc, this is the place to do that

// increment the index anticipating starting the next movieclip in mcA

index++;

// if there's another mcA element left to play, play it

if(index<mcA.length){

playF();

} else {

// all done.  do something?

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2013 Feb 12, 2013

Thank you for your reply, but it won't work.

I got this error.

TypeError: Error #1034: Error forced conversion

I guess it comes from this line

var mcA:Array = a[Math.floor(Math.random()*a.length)];

If you can please tell me how to use this code.

This is the fla file I am working at.

http://www.dotup.org/uploda/www.dotup.org3939431.fla.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2013 Feb 12, 2013

i used mcA for an array reference and you used mcA for a movieclip reference which caused that error:

// an array of arrays.  each element of a is allowable sequence of movieclips

var a:Array=[[mcA,mcB],[mcA,mcB,mcB],[mcC,mcD,mcE],[mcC,mcD,mcD,mcE],[mcC,mcD,mcD,mcD,mcE]];

// mc_A is a randomly chosen element of a.  ie, one of the allowable sequences of movieclips

var mc_A:Array=a[ Math.floor(Math.random()*a.length)]

// the movieclips in mcA will be played from the first until the last

var index:int=0;

var mc:MovieClip;

// playF starts the next movieclip in mcA playing (and as i'm typing this i realize i failed to add an mc.play() in playF)

playF();

function playF():void {

mc=mc_A[index];

// start it playing

mc.gotoAndPlay(2);

// if mc needs to be added to the stage or needs to be made visible etc, this is the place to do that

// add a loop to check when it finishes playing so we can start the next movieclip in mcA

mc.addEventListener(Event.ENTER_FRAME,enterframeF);

}

function enterframeF(e:Event):void {

// check if mc has completed play

if (mc.currentFrame==mc.totalFrames) {

// if so, remove the listener

mc.removeEventListener(Event.ENTER_FRAME,enterframeF);

// if mc no longer needs to be on stage or no longer needs to be visible etc, this is the place to do that

// increment the index anticipating starting the next movieclip in mcA

index++;

// if there's another mcA element left to play, play it

if (index<mc_A.length) {

playF();

} else {

// all done.  do something?

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2013 Feb 13, 2013

Thank you. I really need to study more to understand your script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2013 Feb 13, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines