Skip to main content
Participant
April 30, 2013
Question

Overlapping rain...

  • April 30, 2013
  • 1 reply
  • 667 views

Hi I am very new to this and keep getting the problem of the raindrops in my movie overlaps every time the clip loops, and after about 5 loops/plays the rain clutters the stage and

performance/everything is slowing down. How do I restart the rain array animation for every replay? I hope someone can help me in this matter, because I have a client waiting for me to resolve this... To make myself clear: What I need is the rain to be constant, and not add more and more rain as the replays go on.

Here is the code, it is from the Rain-template in Cs6.

// Number of symbols to add.

const NUM_SYMBOLS:uint = 175;

var symbolsArray:Array = [];

var idx:uint;

var drop:Rain;

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

    drop = new Rain();

    addChild(drop);

    symbolsArray.push(drop);

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

    setTimeout(randomInterval, int(Math.random() * 1000), drop);

}

function randomInterval(target:Rain):void {

   

    // Set the current Rain 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);

Hoping for some solution to keep it nice and constant played as a flashbanner ad.

Kris

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 30, 2013

when you want to remove the rain, use:

function removeF():void{

for(var i:int=symbolsArray.length-1;i>=0;i--){

removeChild(symbolsArray);

symbolsArray.splice(i,1);

}

or, you may want to edit symbolsArray usually by removing elements that are no longer visible on the stage.

KAgentaAuthor
Participant
May 2, 2013

Hey Kglad! I thank you for your answer. I tried to put this code after my original rain but I get :

Scene 1, Layer 'Actions', Frame 11084: Syntax error: expecting rightbrace before end of program.

This is due to the lack of my coding skills, and I have no clue where that rightbrace should go.. Is there any simple rule I should learn?

Kris

KAgentaAuthor
Participant
May 2, 2013

Got the syntax error solved by adding an additional rightbrace after your code.

It still clogs up after about 10-12 replays, which is A LOT better than after just 5 times like before. Any ideas how to tweak it further?

And how to edit the symbolsArray to remove what is no longer visible on stage?

I really appreciate your help

Kris