Skip to main content
Participant
November 27, 2013
Question

Multiple ActionScript on the same flash document

  • November 27, 2013
  • 1 reply
  • 532 views

Hi, everyone. I am very new in flash, and espcially in actionscript.

I have been able to insert the template of snow with the action layer that comes with it. Using these layers alone with the rest of the project. Everything works fine. But when I create other keyframes with action of blinking stars on the same project. Even if they are on the same action layer or on differents layers, the actionscripts of the blinking stars work, but the one with the snow doesn’t work anymore.

I put my actions script below, can someone help me with this problem.

SNOW

// Number of symbols to add.

const NUM_SYMBOLS:uint = 75;

var symbolsArray:Array = [];

var idx:uint;

var flake:Snow;

for (idx = 0; idx < NUM_SYMBOLS; idx++) {

    flake = new Snow();

    addChild(flake);

    symbolsArray.push(flake);

    // Call randomInterval() after 0 to a given ms.

    setTimeout(randomInterval, int(Math.random() * 10000), flake);

}

function randomInterval(target:Snow):void {

   

    // Set the current Snow instance's x and y property

          target.x = Math.random()* 550-50;

    target.y = -Math.random() * 200;

 

          //randomly scale the x and y

          var ranScale:Number = Math.random() * 3;

          target.scaleX = ranScale;

           target.scaleY = ranScale;

 

          var tween:String;

          // ranScale is between 0.0 and 1.0

          if (ranScale < 1) {

                    tween = "slow";

 

          // ranScale is between 1.0 and 2.0

          } else if (ranScale < 2) {

                    tween = "medium";

 

          // ranScale is between 2.0 and 3.0

          } else {

                    tween = "fast";

 

          }

    //assign tween nested in myClip

          myClip[tween].addTarget(target);

 

}

BLINKING STARS

for (var m =0;m<50;m++) {

star1_mc.duplicateMovieClip("star1_mc"+m,m,{_x:Math.random()*350,_y:Math.random()*150});

root["star1_mc"+m].gotoAndPlay(random(30));

}

Thanks in advance

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
November 27, 2013

you cannot use identical function names.  once a (anonymous) function is defined in a frame, it exists for as long as your swf is open whether the frame that contains its code is played or not.

so, remove functions (eg, randomInterval) that have already been defined.  you should be seeing error messages telling you that you have duplicate functions.

jost65Author
Participant
November 27, 2013

Thanks kglad...

Si I can have different setting of intervals for both (random), if i take out the one on the actionscript Blinking Stars

jost65Author
Participant
November 27, 2013

Sorry..

So How can I have....