Jump to content

Flash Actionscript in MX2004


Recommended Posts

ok i've designed a flash movie with one layer with a movie clip which is a snowflake with this code

onClipEvent(load) {
this._x = Math.random()*200 // 0 to 200
this._y = Math.random()*200 // 0 to 200
speed = Math.random()*3+3; // 3 to 6
drift = Math.random()*2-1; // -1 to 1
rotate = Math.random()*6-3; // -3 to 3
}
onClipEvent(enterFrame) {
this._y += speed;
this._x += drift;
this._rotation += rotate;

//bring back to top
if (this._y > 200) this._y =0;
 
 //one side to another
 if (this._x < 0) this._x = 200;
 if (this._x > 200) this._x = 0;
}
 

on the root layer i have this code

MovieClip.prototype.randomRGB = function(){//adds a random RGB to the movie clip
(new Color(this)).setRGB(Math.random()*0xFFFFFF);
}
snowflake.onEnterFrame = this.randomRGB;
//creating a key listener. The movie response to the hit of the spacebar. Hitting the spacebar triggers an event
spaceBar = new Object();

spaceBar.onKeyDown = function(){

if (Key.getCode() == 32){//32 is the number that corresponds to the spacebar.
 
 randomRGB;// this changes the size of the grid for the duplicated movieclip.
}
}

Key.addListener(spaceBar);//this registers the 'spaceBar' to receive key event onKeyDown.

// create 30 snowflakes
for(var i=0;i<30;i++) {
snowflake.duplicateMovieClip("snowflake"+i,i);
}

However it doesnt work how i want it to. I want the movie clip to listen to the spacebar and when pressed all of the snowflakes change to a random colour.

Here is the .fla

Anything would be appreciated. Thanks

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...