Be a Supporter!

Button playing a sprite

  • 226 Views
  • 7 Replies
New Topic Respond to this Topic
Anime4Life
Anime4Life
  • Member since: Sep. 4, 2005
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Button playing a sprite 2009-07-13 17:50:23 Reply

Okay so this is probably very easy and I am just blanking on how to do it, but each time a certain button is clicked I want a sprite I have to play its short animation .

Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Button playing a sprite 2009-07-13 17:56:28 Reply

As2.0

Put:

stop();

On the first frame of the animation. Then, put this on the button

on(release)
{
nameOfClip.play();
}

where nameOfClip is the instance name of the clip you've created.


Perpetually looking for time to return to the arts.

BBS Signature
Anime4Life
Anime4Life
  • Member since: Sep. 4, 2005
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to Button playing a sprite 2009-07-13 18:15:28 Reply

That answered my question perfectly. Thank you.

...But now that I have it set up I am a little disappointed. I was hoping/expecting that each time I clicked the button it would play the sprite and if it was clicked rapidly that the little "+1" animation would overlap a bit, instead it seems to wait for the animation to stop before starting another one.

Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Button playing a sprite 2009-07-13 18:17:46 Reply

Try:

nameOfSprite.gotoAndPlay(1);

Which will reset to the first frame every time the button is clicked.


Perpetually looking for time to return to the arts.

BBS Signature
Anime4Life
Anime4Life
  • Member since: Sep. 4, 2005
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to Button playing a sprite 2009-07-13 18:32:20 Reply

Hmmm that is closer to what I want and if I have to I wouldn't be devastated staying with this, but I was hoping that it would play the animation each time it was clicked with overlapping. Did a quick crappy picture of what it would kinda look like.

Button playing a sprite

Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Button playing a sprite 2009-07-14 11:37:00 Reply

That would require creating duplicates of the object. Something like this:

Main Timeline

counter = 0;

Button

on(release)
{
var clip = duplicateMovieClip("instanceName", "instanceName"+counter, counter);
clip.play();
counter++;
}

And on the last frame of the clip itself:

this.removeMovieClip();

Some of my syntax might be wrong. haven't worked with AS2.0 in quite some time.


Perpetually looking for time to return to the arts.

BBS Signature
MrNine
MrNine
  • Member since: Jul. 4, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to Button playing a sprite 2009-07-14 12:54:13 Reply

At 7/14/09 11:37 AM, Johnny wrote: That would require creating duplicates of the object. Something like this:

Main Timeline

counter = 0;

Button

on(release)
{
var clip = duplicateMovieClip("instanceName", "instanceName"+counter, counter);
clip.play();
counter++;
}

And on the last frame of the clip itself:

this.removeMovieClip();

Some of my syntax might be wrong. haven't worked with AS2.0 in quite some time.

Wouldn't he have to put something like _root.['instanceName"+counter]. play instead of clip.play

Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Button playing a sprite 2009-07-14 17:49:16 Reply

At 7/14/09 12:54 PM, MrNine wrote:
Wouldn't he have to put something like _root.['instanceName"+counter]. play instead of clip.play

Not if you create a local variable for it like I did...

By saying

var thingy = attachMovieClip() //or duplicate

You can access properties of that attached clip immediately by using 'thingy.'

Though, you try and access it outside of it's local function, or later down the line, you couldn't.
You could however do something like this later.

for(i = 0; i < 100; i++)
{
var thingy = _root["thing+i"]
thinggy.x = whatever.
}

To achieve the same thing.


Perpetually looking for time to return to the arts.

BBS Signature