# Changing button's image

**URL:** <https://forum.kirupa.com/t/changing-buttons-image/8402>\
**Category:** flash\
**Created:** [November 20, 2002, 8:29am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402 "2002-11-20T08:29:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ewyong](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@ewyong](https://forum.kirupa.com/u/ewyong)\
**Post date:** [November 20, 2002, 8:29am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/1 "2002-11-20T08:29:30Z")

</div>

Hi,

I need help from the experts here. Well, I am not that familiar with Flash Scripting and I need to do some scripting here I think.

I want to create a button with 2 images where when we click on it, the image of the button changes. Something like control buttons to control a movie. When we click on the Pause button, it changes to a Play button, and when click on the Play button, it goes back to the Pause button. Anyone can help me here. Thanks in advance. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 9:02am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/2 "2002-11-20T09:02:47Z")

</div>

here’s a way:

make a movie with two frames, one for on, one for off.

select the movie and put this in the actions panel:

```auto

onClipEvent(load){
   stop();
   this.onPress = function(){
      this.gotoAndStop(!(this._currentframe-1)+1);
   }
}

```

that’ll do it!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 9:19am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/3 "2002-11-20T09:19:45Z")

</div>

Hi sbeener,

Thanks for the code. It works. I really have alot to learn about Flash Action scripting.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 9:29am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/4 "2002-11-20T09:29:13Z")

</div>

Hey sbeener, you can use button handlers on movie clips as well, so you don’t need the this.onPress you can just do

on (press){//stuff}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 10:03am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/5 "2002-11-20T10:03:42Z")

</div>

great. i guess i’m just set in my ways… ; )

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 10:05am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/6 "2002-11-20T10:05:44Z")

</div>

Phew… I thought you were going to prove me wrong and that your way was better…lol.

I was waiting for it 🙂

I know I used the method you used, until I accidently put buttons handlers on a movie clip and realized it worked just the same…lol.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 10:13am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/7 "2002-11-20T10:13:04Z")

</div>

Hi guys,

Well, I tried the code and it works great. But I got one small problem. I tried to put in the control to control a keyframe but I can’t stop or play a movie clip.

At the moment, I have a movie clip with some animaitons, and the button that I have created is another movie clip in this movie clip. So, how can I overcome this problem? Thanks again in advance. =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 10:21am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/8 "2002-11-20T10:21:32Z")

</div>

So your button is actually a movie clip inside a movie clip?

And what you want this button to do is???

Sorry it is 4:15am here, I really need to get to bed (very long day). Maybe sbeener will reply back 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 22, 2002, 5:48am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/9 "2002-11-22T05:48:30Z")

</div>

hey lost, i was messin around witht he code as well,  
i replaced this.onPress  
with  
on (Press)

and it said that u cant bundle the on operator

meaning that the onClipEvent (load) and on (press) handlers were conflicting  
whats up witht that? hehe

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 22, 2002, 5:49am UTC](https://forum.kirupa.com/t/changing-buttons-image/8402/10 "2002-11-22T05:49:35Z")

</div>

You don’t put on (press) inside of the onClipEvent handler you put it as its own handler.
