简体   繁体   中英

Flex: Highlighting element on mouse over

I have a canvas with several small canvases on it.

Like this:

public class Board extends Canvas
{
    public function Board()
    {
        //cellWidth = this.width/boardSize;
        //this.drawMech();
        addEventListener(FlexEvent.CREATION_COMPLETE, creationComplete);
        super();
    }

then I added balls to the board using this.addChild(ball);

And ball

public class Ball extends Canvas
{       
    public function Ball()
    {
        addEventListener(FlexEvent.CREATION_COMPLETE, creationComplete);
        super();
    }

    public function creationComplete(event:Event):void
    {
        trace("created stones");
        //Alert.show("Creation complete ever called");
        addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
        //addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
    }

What I want to implement is:

I want the ball which I added to canvas Board, became highlighted (eg changed it's color) on mouse over on it, and became unhighlighted after mouse is go out of ball.

What I have done to achieve it. I added 2 event listeners to ball class, in order to listen for mouse over and mouse out events...But for some reason they was not called.

Your class's name is Ball and constructor's name is Stone . The line addEventListener(FlexEvent.CREATION_COMPLETE, creationComplete); will never be called. Change the constructor name to Ball.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM