Coding Events in classes!

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 :slight_smile:

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 :slight_smile:

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 :slight_smile:

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