Forum Moderators: open

Message Too Old, No Replies

Randomizing X and Y in flash

         

supermanjnk

12:23 pm on Sep 27, 2006 (gmt 0)

10+ Year Member



I'm pretty new to action script, but I do have knowledge in Javascript which I understand is syntactically similar.

This is the code that I have

kNbrSymbols = 5;
kSymbolLayer = 100;

SW = 780; // keep track of width and height of stage
SH = 100;

// move symbols to the right
moveSymbol = function()
{
this._x += this.speed;
if (this._x > SW+10)
this._x = -10;
}

// Initial Symbol setup
for (i = 0; i < kNbrSymbols; ++i) {
mc = _root.attachMovie('symbols'+i, 'symbol_'+i, kSymbolLayer+i);
mc._x = random(SW);
mc._y = random(SH);
mc._xscale = mc._yscale = 50;
mc._alpha = 50 + random(50);
mc.speed = random(10)+1;
mc.onEnterFrame = moveSymbol;
}

This works great for scrolling the symbols across the page, However I want them to randomly appear,

I found some code which does what I want if you place a symbol in the fla file and add it to the action script of the symbol.

onClipEvent (enterFrame) {
_alpha = random(100);
_x = _x=random(780);
_y = _y=random(100);
_yscale = 50+random(100);
}

I would like to find a way to implement this into the code at the top. As well as slow down the rate at which they appear and disappear.
I would also like to make it so that xscale scales with the _yscale so the symbols aren't distorted.

Any help would be great.