PDA

View Full Version : confused about on(release)


Goosey
02-11-2003, 04:28 AM
Im really confused about one thing: using the technique of

on(release){
_root.gotoAndPlay(x);
}

in a button works perfectly, however the same code will fail to function in a movieclip.

If i use the technique of

onClipEvent (mouseUp) {
checkX = _root._xmouse;
checkY = _root._ymouse;
if (this.hitTest(checkX, checkY, true)) {
_root.gotoAndPlay(2);
}
on a movieclip then it will work perfectly.

ok everything so far seems to tell me that on(release) something that should be used only with buttons.... BUT there is a wildcard thrown in:
if I do:

on(release){
trace("YEA IM HERE TO CONFUSE YOU!");
_root.gotoAndPlay(x);
}

then you will get "YEA IM HERE TO CONFUSE YOU!" in the output window... So how exactly does on(release) work with movieclips? It seems that maybe it works fine with some commands and not others?

Im sorry if I sound like a total newbie (but I am, and this is the newbies forum right?).. this just really confuses me.

I suppose I can use the mouse-x-y-hit-detection technique whenever I want to use a movieclip as a button (or embed a button in the movieclip), but really.. why doesn't on(release) function as one expect it would?

/Pyro
02-11-2003, 11:41 AM
I'm a newbie myself, but I have had trouble with what you are talking about as well. In all the tutorials I have read they say that you should embed a button in a movie clip if you want a "clickable" movie clip. I have found it to work just fine for me. Now as for why, thats a really question. My guess, is the behavior of a movie clip runs different internal processes than the behavior of a button. Maybe one of the wiser members can clarify for us.

Lolotte
02-11-2003, 12:25 PM
In flash MX, you can make moviesclips act like buttons. Simply set an onRelease event to your movieClip and you have a button!

This code would be placed on the main timeline, giving that your movieclip has an instance name of "myButton_mc":

myButton_mc.onRelease = function(){
// put your actions here
}

This also gives you the opportunity to set different behaviors to different button states, like:

myButton_mc.onRollOver = function(){
// put some other actions here
}


You can use this code for buttons (the good old ones), but again it has to be on the timeline, not on the button. It is good practice to put all your code on the timeline anyway.

By the way, if you want to change the look of your movie clip for each state (onRolllOver, onPress), simply add a an "_up", "_over", and "_down" keyframe in your movie clip (make a labels layer and give your keyframes these exact names). Change your movieclip appereance accordingly and voila!. With these keyframe names, you movieclip will automatically go to the corresponding frame when the user roll over or press on the clip (this is a new movieclip built in functionnality). You need to set a event (action) to your mc to see the changing state in action.


Lolotte

linckx
02-11-2003, 12:54 PM
I have noticed that

_root.gotoAndPlay sometimes doesn't work on frame-numbers, so I always use labels, and that seems to help too

robin

Greencardman
02-11-2003, 02:55 PM
Wow, thank you Lolotte. Thats why I come here, to have someone show me something I didn't know before. Then I wonder why the hell I didn't think of that when I was doing that project for so and so which would have been a better way to do it then the newbie workaround I used in its place. So yeah, thanks for that one.

Goosey
02-11-2003, 09:06 PM
Thanx Lolotte that is helpful.

But still I wonder if anyone has an explanation to just WHY gotoAndPlay(); doesnt work when in on(release) events in a movieclip, while trace(); and perhaps other functions do :\

There are tons of workarounds (and Lolotte yours is pretty good), but I really hate working around what seems like it should work.