2

考虑下面的代码:为什么我不能跟踪点击事件?

            package {
                import flash.display.Sprite;
            import flash.events.MouseEvent;
            import flash.display.*;
            [SWF(width="1000",height="600")]
                public class vanCopperTes extends Sprite
                {
                    public function vanCopperTes()
                    {
                        stage.align = StageAlign.TOP_LEFT;
                        stage.scaleMode = StageScaleMode.NO_SCALE;

                        //黄色矩形
                        graphics.beginFill(0xFFCC00,.5);
                        graphics.drawRect(0,0,200,200);
                        graphics.endFill();
                        addEventListener(MouseEvent.CLICK,onClick);
                        trace("this.numChilder",numChildren);// output: 0

                    }

                    private function onClick(e:MouseEvent):void
                    {
                        trace("Click");
                    }

                }
            }
4

1 回答 1

0

尝试将事件监听器更改为:

stage.addEventListener(MouseEvent.CLICK,onClick);

这将适用于整个 .swf。如果你想让它只是黄色方块,你需要将它添加为一个单独的精灵并将监听器附加到它。

于 2012-12-04T14:16:07.590 回答