PDA

View Full Version : OnEnterFrame function doesn't work


Flippie124
11-09-2004, 04:44 PM
Ok, this problem is not so hard to solve I think. I have duplicated a movieclip
9 times. On the last line of my for loop I'm trying to set an OnEnterFrame action for each of the duplicates. Why the hell is this not working??

for(i=1;i<10;i++){
_root.mc0._x = 19;
duplicateMovieClip(_root.mc0,'mc'+i,i);
_root['mc'+i]._x = _root['mc'+(i-1)]._x + 40;
_root['mc'+i].onEnterFrame = rot("mc"+i);
}


function rot(mcname){
_root.mcname._rotation = _root.mcname._rotation + 1;
}

senocular
11-09-2004, 04:46 PM
onEnterFrame is supposed to be a function. What you assigned it to is the return value of a function you manually called, rot("mc"+i); That return value is void and therefore no value is really assigned to onEnterFrame making it not operate

You probably want

_root['mc'+i].onEnterFrame = rot;

which will assign the rot function to the onEnterFrame for that movieclip. However, as an onEnterFrame event, it will have no values passed to it (and never will)l

tg
11-09-2004, 04:49 PM
do what senocular said then change your rot function line to:

this._rotation = this._rotation + 1;

or

this._rotation++;

or

this._rotation+=1;

Flippie124
11-09-2004, 05:03 PM
tnx 4 u're help! ..... I thought that if you specify a function on the right hand side of OnEnterFrame, that function will be executed each time the movieclip enters a frame. ... If you write OnEnterFrame = function(){ -code -}, the code is executed on each frame.

ok :) ...so onEnterFrame is the actual function and you have to specify the contents. What I was trying to do is impossible because I'm trying to assing a function to the contents of a function?

By doing onEnterFrame = rot; I'm actually saying:"paste the content of the function rot to the content of function onEnterFrame";

Is this correct or I'm I using stupid logic? :)

skjc
11-09-2004, 07:27 PM
I am not entirely sure what you are trying to do. Are you generating the duplicate mcs and then allowing the user to rotate them when they click on the mc?

If so here is some code that might help. There are two buttons as well which allow the user to duplicate the mc on demand and then remove them if they want.

The drawback here is that the onRelease event is on a specific named instance of an mc which means naming all of the mcs.

//on a button allow the user to duplicate the clips - you do not need
// a button for this you can just do it on entering a specific frame

duplicate_btn.onRelease = function() {
for(i=1;i<10;i++){
_root.mc0._x = 19;
duplicateMovieClip(_root.mc0,'mc'+i,i);
_root['mc'+i]._x = _root['mc'+(i-1)]._x + 40;
}
}

//likewise for the removal of the mcs

remove_btn.onRelease = function() {
for(i=1;i<10;i++){
removeMovieClip("_root.mc"+i)
}
}

//targets a particular mc and rotates it on release

_root.mc0.onRelease = function() {
_root.mc0._rotation += 20;
}
//and so on for the other instances of the mc. Note that mc0 will always
//appear