-
Adding onLoad and onEnterFrame handlers to dynamic clips?
Hi.
I'm making a game where a laser is fired upon pressing the ctrl key. The laser is attached using attachMovie. I want to define a variable to the clip upon it loading and make it movie across the screen upon enterFrame. I know how to make it go across the screen and define the variable but i'm having trouble figuring out how to do this using attached movie clips. I'm using code like:
PHP Code:
_root["laser"+lasercounter].onEnterFrame {
but that doesn't work.
Any ideas?
Thanks a lot
-
ʞ33ƃ
PHP Code:
_root["laser"+lasercounter].onEnterFrame=function(){
//do whatever
}
-
Senior Member
or
PHP Code:
clip.onEnterFrame = something;
function something() {
// do something!
}
this way you can command different clips with the same function
n.b dont put parentheses when you call the function in that way
-
Thanks for replying
Does that mean that if i want to use attachMovie i can only use functions to do the various actions or is there another way?
Thanks
-
Senior Member
you can put a
this.onEnterFrame=function() {
//stuff
}
inside the clip, this will fire when it comes on stage
or put a containter clip with actions referring to the _parent
-
Thanks
I've tried using a function for the laser but it still won't work and i can't figure out why
Can you please have a look at it and see if you can spot the problem. It's probably simple but i can't see it.
PHP Code:
onClipEvent(load) {
speed = 10;
lc = 1;
laserspeed = 20;
function laserfunction() {
_root["laser"+lc]._x += laserspeed;
if(_root["laser"+lc] >= 600) {
_root["laser"+lc].removeMovieClip();
}
}
}
onClipEvent(enterFrame) {
if(Key.isDown(Key.LEFT)) {
this._x -= speed;
}
if(Key.isDown(Key.RIGHT)) {
this._x += speed;
}
if(Key.isDown(Key.UP)) {
this._y -= speed;
}
if(Key.isDown(Key.DOWN)) {
this._y += speed;
}
if(Key.isDown(Key.CONTROL)) {
attachMovie("laser","Laser"+lc,lc)
_root["laser"+lc]._x = spaceShip._x;
_root["laser"+lc]._y = spaceShip._y;
_root["laser"+lc].onEnterFrame = laserfunction();
lc++;
}
}
Thanks a lot
-
mbenney
n.b dont put parentheses when you call the function in that way
CTT_Mustapha
_root["laser"+lc].onEnterFrame = laserfunction ();
also, the laserfunction function won't know what "lc" is, i think (but not 100% sure) you should just use
this._x += laserspeed; etc
also, there should be an "_x" >= 600 in the if statement in the laserfunction function methinks???
-
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|