# Coding Events in classes!

**URL:** <https://forum.kirupa.com/t/coding-events-in-classes/59854>\
**Category:** flash\
**Created:** [August 4, 2004, 12:01pm UTC](https://forum.kirupa.com/t/coding-events-in-classes/59854 "2004-08-04T12:01:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sim085](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@Sim085](https://forum.kirupa.com/u/Sim085)\
**Post date:** [August 4, 2004, 12:01pm UTC](https://forum.kirupa.com/t/coding-events-in-classes/59854/1 "2004-08-04T12:01:40Z")

</div>

Hi, im still working on these classes but now I am trying to handle event of buttons which I have created in the classes. The following is the code I used to create a simple movie clip that has a square in it (Which I need it to be like a button)

[font=Courier New][color=slategray]// Creating a movieclip in parent called Button1[/color][/font]  
[font=Courier New]parent.[color=navy]createEmptyMovieClip[/color]([color=blue]“Button1”[/color], 1);[/font]  
[font=Courier New]Button1 = parent.Button1 [color=slategray] // Refreshing global variable.[/color][/font]  
[font=Courier New][color=slategray]// Creating a small box coloured Red[/color][/font]  
[font=Courier New][color=navy]with/color{[/font]  
[font=Courier New][color=navy]lineStyle/color;[/font]  
[font=Courier New][color=navy]beginFill[/color](0xcc0000, 100);[/font]  
[font=Courier New][color=navy]moveTo/color;[/font]  
[font=Courier New][color=navy]lineTo/color;[/font]  
[font=Courier New][color=navy]lineTo/color;[/font]  
[font=Courier New][color=navy]lineTo/color;[/font]  
[font=Courier New][color=navy]lineTo/color;[/font]  
[font=Courier New][color=navy]endFill/color;[/font]  
[font=Courier New]}[/font]

The above coding works fine and a small Box appears (I also added some text in the box). Now I wanted that this button could handle MouseOn, MouseOut Events, and when the user goes on the button, the opacity of the button changes. SO i tried this code:

[font=Courier New][color=slategray]// User goes on the mouse on the button[/color][/font]  
[font=Courier New]Button1.[color=navy]onMouseOver[/color] = [color=navy]function/color{[/font]  
[font=Courier New][color=navy]trace/color; [color=slategray]// trace started[/color][/font]  
[font=Courier New]Button1.[color=navy]\_[/color][color=navy]alpha[/color] = 60; [color=slategray]// Changing opacity[/color][/font]  
[font=Courier New][color=navy]trace/color; [color=slategray]// trace ended[/color][/font]  
[font=Courier New]}[/font]

Now when I go on the mouse on th movie clip the trace commands appear but the opacity of the movie remains the same!!! … I wanted that the button could be draged … I don’t know how I can convert this movie into a button. Somthing else I noticed is that when I go on the Button1 the mouse pointer remains an Arrow and does not become a Hand!!!

I hope that someone knows the answer to this problem!!  
Thanks to all 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:** [August 4, 2004, 1:05pm UTC](https://forum.kirupa.com/t/coding-events-in-classes/59854/2 "2004-08-04T13:05:35Z")

</div>

Hi … Ok I found the answer … The code should be as follows:

[color=slategray]// Handling onPress event.[/color]  
[font=Courier New]Button1.[color=navy]onPress[/color] = [color=navy]function/color:Void{  
[color=navy]trace/color;  
[color=navy]this[/color].[color=navy]\_alpha[/color] = 80;  
}[/font]  
Thanks for reading 🙂

---

<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:** [August 4, 2004, 2:08pm UTC](https://forum.kirupa.com/t/coding-events-in-classes/59854/3 "2004-08-04T14:08:08Z")

</div>

if you want to use onMouseOver, onMouseMove, etc, I think you’ll have to add a listener

Mouse.addListener(Button1)

or have that in the class’ constructor as

Mouse.addListener( this )

Try that out 🙂

---

<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:** [August 4, 2004, 2:47pm UTC](https://forum.kirupa.com/t/coding-events-in-classes/59854/4 "2004-08-04T14:47:21Z")

</div>

> [@ahmed](#):
>
> if you want to use onMouseOver, onMouseMove, etc, I think you’ll have to add a listener
> 
> Mouse.addListener(Button1)
> 
> or have that in the class’ constructor as
> 
> Mouse.addListener( this )
> 
> Try that out 🙂

Yes I saw some coding like that … I’ll try it out, at least I learn something new 🙂
