1
votes

I am new to AS3.

For graphical representation I use fla file as a resource. I work in Flash Builder 4.6 to code.

I try to create own class Panel which contains the click event. But event doesn't work when I test the move!

When I move the event handler (buttonClick) and event listener to main class (test) and apply the event to the card object (for example), all works fine.

What is wrong with my code?

My main class of application:

package
{
import flash.display.Sprite;
import flash.events.*;
import flash.ui.Keyboard;

import ui.Panel;

public class test extends Sprite
{
    var card:Panel;

    public function test()
    {
        card = new Panel();
        addChild(card);
    }

}
}

The Panel class:

package ui
{
import flash.display.MovieClip;
import flash.events.*;

public class Panel extends MovieClip
{

    var back:PanelBack;
    var button:PanelButton;

    public function Panel()
    {
        super();
        back = new PanelBack();
        button = new PanelButton();
        addChild(back);
        addChild(button);

        button.addEventListener(MouseEvent.CLICK,buttonClick);
    }

    private function buttonClick(event:MouseEvent):void
    {
        trace("Hello");
    }

}
}
1
try add value button.buttonMode = true , this will display hand cursor and help You manage display list . You will see if Your object is accessable for mouse if cursor will change .turbosqel
no, cursor is the same (not a hand)Jim Exad
What is the base class of PanelButton? Can it actually receive mouse events?laurent
PanelButton is class that I defined in Flash for the symbol.Jim Exad
can you add the PanelButton class please :)xLite

1 Answers

0
votes

enter image description here

Ensure that in the symbol properties, you have your settings configured as shown above. In the "class" section you must explicitly define the class (defined in an external .as file) to link the symbol to the class within the file. Also ensure that in your project directory (where your FLA is) you have a folder named "ui" with a "Panel.as" file where your panel class is defined therein.