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

Play Random Movie Clips by main timeline progress

Participant ,
Aug 13, 2018 Aug 13, 2018

I have 48 movie clips numbered as follows:

Music_mc1, Music_mc2, Music_mc3, etc. to Music_mc48

I need a code that will trigger a random movie clip at each location where the code resides on the main timeline.

Here is what I have:

var SelectMC: Number = 0; {

function GetMC(): void {

var SelRandom: Number = Math.random();

SelectMC = Math.round(SelRandom * 47 + 1);

//trace (SelectMC);

}

GetMC();

var Holder: Object = new Object();

Holder = ("Music_mc" + String(SelectMC));

trace(Holder);

this[Holder].gotoAndPlay(2);

}

By the Output panel, the random MCs are selected correctly. But the swf stops at the first instance of the code (frame 222), and I get this error message:

TypeError: Error #1010: A term is undefined and has no properties.

at Unit19_fla::MainTimeline/frame222()

All help is appreciated!

TOPICS
ActionScript
2.1K
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 , Aug 17, 2018 Aug 17, 2018

Hi.

I'm not sure exactly how you setup the objects in the timeline. So please check if this is what you want.

You can call the function when a button is clicked as well.

AS3 code:

Frame 1:

var total:uint = 3;

function playRandomMovieClip():void

{

     this["Music_mc" + Math.round(1 + Math.random() * (total - 1))].gotoAndPlay(1);

}

Frame 222:

playRandomMovieClip();

FLA download:

animate_cc_as3_play_random_movie_clip.zip - Google Drive

Regards,

JC

Translate
LEGEND ,
Aug 14, 2018 Aug 14, 2018

Where are the mc's located?

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
Participant ,
Aug 14, 2018 Aug 14, 2018

Thanks, Ned.

The movie clips are on a layer of the timeline. That is a single cell that extends from Frame 222 to the end of the timeline.

Each movie clip is 93 frames long with stop(); on Frame 1. The layer in which the movie clips reside has nothing from frames 1-221, and the movie clips are ln frames 222 to the end of the 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
LEGEND ,
Aug 15, 2018 Aug 15, 2018

For the time being, try moving that single cell that holds the movieclips from frame 222 to frame 1 of the main timeline and see if the error persists. 

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
Participant ,
Aug 15, 2018 Aug 15, 2018

Thanks again, Ned!

I moved the movie clip cell to frame 1 and got the same error on frame 222.

then . . .

I moved the AS code to frame 1, got the same error on frame 1, but the test movie plays.

Is that an error I can ignore, since the swf plays?

In continuing to fiddle with this, I moved the AS back to frame 222 and tried the debug test. The debug movie freezes at frame 222, throws the same error, and highlights the following line of the script above:

this[Holder].gotoAndPlay(2);

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
LEGEND ,
Aug 16, 2018 Aug 16, 2018

If you get an error it is best to not ignore it regardless if things play or not.

Try tracing this[Holder] and see what you get.

Also, since Holder is a String, try changing it to be a String rather than an Object.

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
Participant ,
Aug 16, 2018 Aug 16, 2018

Thanks, Ned.

Ned - I found a mc that was not instantiated (is that the right word?). I suspect that was the problem.

I will report back.

Thanks!!

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
Participant ,
Aug 16, 2018 Aug 16, 2018

Ned,

In getting the random call of the movie clips fixed, I seem to have disabled a set of buttons that control another set of movie clips.

My interpretation of what I see is that the memory required to randomize and play the movie clips according to the timeline progress does not leave enough memory for the buttons to function.

Is there a way that I can minimize that problem - or cancel some event listeners to free up the memory required?

Thanks for all of your help?

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
LEGEND ,
Aug 17, 2018 Aug 17, 2018

I doubt there is a memory issue relative to the buttons not working.  I suspect that the buttons were the next thing in line to be fixed and they finally had a chance to make that known.

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 ,
Aug 17, 2018 Aug 17, 2018

Hi.

I'm not sure exactly how you setup the objects in the timeline. So please check if this is what you want.

You can call the function when a button is clicked as well.

AS3 code:

Frame 1:

var total:uint = 3;

function playRandomMovieClip():void

{

     this["Music_mc" + Math.round(1 + Math.random() * (total - 1))].gotoAndPlay(1);

}

Frame 222:

playRandomMovieClip();

FLA download:

animate_cc_as3_play_random_movie_clip.zip - Google Drive

Regards,

JC

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
Participant ,
Aug 18, 2018 Aug 18, 2018

Thanks for the simpler code. What additions to that simple code would eliminate immediate duplications? I don't mind ABA, but I would prefer to avoid AAB or ABB, etc.

I am now having problems with another set of movieclips (13 of them) that run in sync with the main timeline because they have to precisely hide/reveal elements on the main timeline at exact points in the timing/progress of the printed music. I have used buttons to make them visible or invisible as needed, but they are always running to ensure synchronization with the main timeline. That is an issue that may be requiring lots of memory.

I am working through that issue. Before I am finished, I am almost certain that I will be back to this string for one problem or the other.

Thanks again - to JC and Ned.

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 ,
Aug 18, 2018 Aug 18, 2018

For the randomization, you could store the possible indexes in a array and then randomize it every time all the values are picked.

if (!this.started)

{

    var total:uint = 3;

    var indexes:Array = [];

    var count:uint = 0;

    for (var i:int = 0; i < total; i++)

          indexes = i + 1;

    randomizeArray();

    this.started = true;

}

function playRandomMovieClip():void

{

    var index:uint = ++count % total;

    this["Music_mc" + indexes[index]].gotoAndPlay(1);

    if (index == 0)

          randomizeArray();

}

function randomizeArray():void

{

    indexes.sort(function(a:*, b:*):int

    {

         if (Math.random() < 0.5)

              return -1;

         else

              return 1;

    });

}

About the other issues, I'll need to see your FLA.

Regards,

JC

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
Participant ,
Aug 18, 2018 Aug 18, 2018

I am going to need help with those buttons. There are 13 of them, and only one of them functions as it should. The others don't even respond as it should to the roll-over stage.

I can put the fla on my server if that is OK.

Suggestions are 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
Community Expert ,
Aug 19, 2018 Aug 19, 2018

Hi.

Sure. You can put on your server or somewhere else.

Thanks,

JC

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
Participant ,
Aug 19, 2018 Aug 19, 2018

Thanks!!  Here is a link to the fla.

https://www.rhythmbee.com/programs/12876/download

My problem is that the 14 red and white buttons at the bottom of the screen should be active from 222 on.  As is, they are not useable.

Thank you!!

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
Participant ,
Sep 08, 2018 Sep 08, 2018
LATEST

Thanks to all who have responded.

As always, we learn a lot by letting the end user tell us what he/she needs next.

I need code that will let a single button pause the main timeline and the currently playing movieclip(s). (It may be one or two.)

I tried pausing all timelines (main and movieclips) by giving instructions such as:

stop();

Music_mc1.stop();

Music_mc2.stop();

Music_mc3.stop();

Music_mc4.stop();

Music_mc5.stop();

Music_mc6.stop();

Music_mc7.stop();

Music_mc8.stop();

Music_mc9.stop();

etc. through all 48 movie clips.

That works to stop everything in it's tracks. But strange things happen when I restart with the "play" button.

I also tried letting the pause button change the fps to zero. That also works, but then I need the play button to restore the previous fps, which may be anything from 10fps to 60 fps, depending on the music tempo that the user has selected before the pause.

Thanks for the great assistance in the past. I look forward to your answer.

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