PDA

View Full Version : code on main timeline [MX]


friz2002
12-08-2002, 09:10 PM
I have an mc on the main timeline with this code on the timeline of the mc

function naarRechts(){
this._x +=snelheid;
teVer();
}
function teVer(){
if(this._x>=500){
this._x = -33;
this._y = random(400);
}
}
_root.xpos = Math.round(this._x);
_root.ypos = Math.round(this._y);


this code is on the mc

onClipEvent(load){
snelheid = 5;
}
onClipEvent(enterFrame){
naarRechts();
}
onClipEvent(keyDown){
snelheid +=5;
}

Is there a way to put all this script neatly together on the Main Timeline???

Thx in advance

jimburton
12-08-2002, 10:29 PM
function naarRechts(){
this._x +=snelheid;
teVer();
}
function teVer(){
if(this._x>=500){
this._x = -33;
this._y = random(400);
}
}
_root.xpos = Math.round(this._x);
_root.ypos = Math.round(this._y);

my_mc.snelheid = 5;
my_mc.onEnterFrame = naarRechts;
my_mc.onKeyDown = function() {
this.snelheid +=5;
}

nb: my_mc.onLoad wouldn't work properly so you need to set the initial value of your var manually, as it were.

friz2002
12-08-2002, 11:01 PM
Hi,
thx for the quick answer.
I thought it would look something like this. But I couldn't get it to work.
I copied your code to my main timeline (first frame, as there's only 1) and changed my_mc to raket_mc (the instancename of my mc)

But it too didn't work:(

Then I changed
raket_mc.onEnterFrame = naarRechts;
into
raket_mc.onEnterFrame = naarRechts();
also tried with
_root.raket_mc.onEnterFrame = naarRechts();

but still nothing
:confused:

I included the fla .
Would appreciate further help on this.
Again, Thx in advance

jimburton
12-09-2002, 12:27 AM
this works:

function naarRechts(){
this._x +=this.snelheid;
if (this.snelheid > 5) this.snelheid--;
this.teVer();
}
function teVer(){
if(this._x>=500){
this._x = -33;
this._y = random(400);
}
}
//_root.xpos = Math.round(this._x);
//_root.ypos = Math.round(this._y);

raket_mc.snelheid = 5;
raket_mc.onEnterFrame = naarRechts;
raket_mc.teVer = teVer;
raket_mc.onKeyDown = function() {
this.snelheid +=5;
}
Key.addListener(raket_mc);


added a line to slow down the rocket when the key is no longer being pressed...remove if that's not what you want.

friz2002
12-09-2002, 06:30 PM
Thx Jim :)