识别对象已点击

时间:2011-03-17 07:33:07

标签: actionscript-3 event-handling blackberry-playbook

我正在为Blackberry Playbook开发ActionScript 3。我是ActionScript 3开发的新手。

我有这个:

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;

    [SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
    public class Transition extends Sprite
    {
        private var imageBack:Loader;
        private var imageFront:Loader;

        public function Transition()
        {
            super();
            createGUI();

            imageBack.load(new URLRequest("assets/images/back.png"));
            imageFront.load(new URLRequest("assets/images/front.png"));

        }

        private function createGUI():void {
            imageBack = new Loader();
            imageBack.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedEvent);
            imageBack.addEventListener(MouseEvent.CLICK, onImageClicked);

            imageFront = new Loader();
            imageFront.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedEvent);
            imageFront.addEventListener(MouseEvent.CLICK, onImageClicked);
        }

        private function onLoadedEvent(event:Event):void {
            // Blah, Blah, Blah...
        }

        private function onImageClicked(event:MouseEvent):void {
            var currentTarget:Loader = Loader(event.currentTarget);
        }
    }
}

我想确定在onImageClicked函数中点击了哪个图片。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

你可以为每个Loaders指定一个name并检查它(或检查它而不指定 - 默认情况下它们会有不同的名称):

switch((event.currentTarget as Loader).name){
    case imageBack.name:
    trace('imageBack here');
    break;

    case imageFront.name:
    trace('imageFront here');
    break;
}