Movieclip code error

Started by: Apples | Replies: 5 | Views: 556

Apples
2

Posts: 1,931
Joined: Dec 2005
Rep: 10

View Profile
Jul 26, 2008 12:02 AM #198168
I have this code in a movie clip:
on (press) {
gotoAndPlay(2);
}
{tellTarget ("cursor")
{gotoAndPlay(2);
}}

It is supposed to make the cursor play when pressed, and at the same time make the movie clip the code is in, play.
It wont work...
Anyway this can be fixed?
darkcampainger
2

Posts: 159
Joined: Aug 2006
Rep: 10

View Profile
Jul 26, 2008 4:45 AM #198285
Quote from Apples
I have this code in a movie clip:
on (press) {
gotoAndPlay(2);
}
{tellTarget ("cursor")
{gotoAndPlay(2);
}}


Please put your script in [noparse]
 and 
[/noparse] tags, it makes it more defined and preserves spacing.

Quote from Apples
It is supposed to make the cursor play when pressed, and at the same time make the movie clip the code is in, play.
It wont work...
Anyway this can be fixed?


Well, it should be outputting some errors, to, since the 'on ()' handler is only supported for buttons, and not MovieClips. Also, tellTarget is an old, old, old function that should not be used any longer. I don't know where you got it from, but it's AS1.0! I actually had to look it up! :P

Here's what you need to do: you must define the onRelease function for the MovieClip when it loads:

onClipEvent(load) {
onRelease = function () {

}
}


The innermost function will be called when the player releases the left mouse button over the MovieClip. Now we just need to play the animations:

onClipEvent(load) {
onRelease = function () {
gotoAndPlay(2);
_root.cursor.gotoAndPlay(2);
}
}


Normally, when referencing an element, you use the "." operator, which defines relationships, like a family tree. So above, the line "_root.cursor.gotoAndPlay(2)" is telling Flash that the object we are referencing is a descendant of _root (the base, anything placed directly on stage is in _root) called "cursor". They can be long, short, or left out. By default, a relation starts at "this", which is the element the ActionScript is being run from. There are special relations, such as _root and _parent. _root will jump you back to base, which great when you need to reference an element that is on a different branch of the family tree. _parent lets you go in reverse one step.

Good luck.
Kitsune
2

Posts: 6,011
Joined: May 2006
Rep: 10

View Profile
Jul 26, 2008 6:57 AM #198339
What would happen if one put the latter code you put in your post in an onClipEvent(enterFrame){} handler? Would it be the same?
Apples
2

Posts: 1,931
Joined: Dec 2005
Rep: 10

View Profile
Jul 26, 2008 3:12 PM #198577
Quote from darkcampainger
Please put your script in [noparse]
 and 
[/noparse] tags, it makes it more defined and preserves spacing.



Well, it should be outputting some errors, to, since the 'on ()' handler is only supported for buttons, and not MovieClips. Also, tellTarget is an old, old, old function that should not be used any longer. I don't know where you got it from, but it's AS1.0! I actually had to look it up! :P

Here's what you need to do: you must define the onRelease function for the MovieClip when it loads:

onClipEvent(load) {
onRelease = function () {

}
}


The innermost function will be called when the player releases the left mouse button over the MovieClip. Now we just need to play the animations:

onClipEvent(load) {
onRelease = function () {
gotoAndPlay(2);
_root.cursor.gotoAndPlay(2);
}
}


Normally, when referencing an element, you use the "." operator, which defines relationships, like a family tree. So above, the line "_root.cursor.gotoAndPlay(2)" is telling Flash that the object we are referencing is a descendant of _root (the base, anything placed directly on stage is in _root) called "cursor". They can be long, short, or left out. By default, a relation starts at "this", which is the element the ActionScript is being run from. There are special relations, such as _root and _parent. _root will jump you back to base, which great when you need to reference an element that is on a different branch of the family tree. _parent lets you go in reverse one step.

Good luck.


Sorry for the confusion, but its actually the code on a button...
:P
darkcampainger
2

Posts: 159
Joined: Aug 2006
Rep: 10

View Profile
Jul 26, 2008 4:49 PM #198634
Quote from Kitsune
What would happen if one put the latter code you put in your post in an onClipEvent(enterFrame){} handler? Would it be the same?

Are you referring to this code?

onClipEvent(load) {
onRelease = function () {
gotoAndPlay(2);
_root.cursor.gotoAndPlay(2);
}
}


If you put the entire onRelease function in it, would work, but it would be poor design. This way, onRelease is defined once. If you used enterFrame, it would needlessly be defining it every frame. I doubt you would see much of a performance change, but you should always strive to optimize your script as much as possible.

If you meant just the gotoAndPlay() parts, no, it would not work. From what I understood, he wants them only to play when a player clicks the button, not every frame (which would also make it appear frozen, since it would be sent to frame 2 again and again, preventing it from reaching frame 3.)
darkcampainger
2

Posts: 159
Joined: Aug 2006
Rep: 10

View Profile
Jul 26, 2008 4:55 PM #198640
Quote from Apples
Sorry for the confusion, but its actually the code on a button...
:P


>:(
Please be clearer in the future :(

Anyways, I've decided it's easiest to do from a MovieClip, so, if you haven't defined Over, Down, and Hit states, just break it apart and re-convert it to a MovieClip. If you have, well, I'll write up a new answer if and when you tell me.