AS3传递自定义事件数据问题

AS3传递自定义事件数据问题

本文介绍了AS3传递自定义事件数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从1级传递自定义事件数据到其他类...这是我的codeS。

I am trying to pass custom event data from 1 class to another class...here is my codes..

a.as

private function onClick(event:MouseEvent):void{
   dispatchEvent(new YouTubeSearchEvent(YouTubeSearchEvent.CHANGE_VIDEO_READY, videoId));
    }

b.as

b.as

private var newVideoID:String;

public function get selectedVideoID():String{
        return newVideoID;
    }


private function buildSingleCont(videoResult:Array):void{

    tn=new a();
    addChild(tn);
    tn.addEventListener(YouTubeSearchEvent.CHANGE_VIDEO_READY, getNewVideoID);

}

private function getNewVideoID(event:YouTubeSearchEvent):void{
        newVideoID=event.videoResult;

}

c.as

c.as

 // this is the main class.....
private var newvideoida:String;
public function c(){
 createSearchContainer()  //this method is called before b.as and c.as are called...
}

private function createSearchContainer():void{
        searchContainer=new b();
        newvideoida=searchContainer.selectedVideoID; //I want to get b.as newVideoID variable
        trace(newvideoida);  //display nothing.....

        addChild(searchContainer);

        }

包com.search.events{    进口对象类型:flash.events.Event;

package com.search.events{ import flash.events.Event;

public class YouTubeSearchEvent extends Event
{
    public static const FEED_VIDEO_READY:String="feed_video_ready";
    public static const CHANGE_VIDEO_READY:String="change_video_ready";

    public var videoResult:*;

    public function YouTubeSearchEvent(type:String, videoResult:*)
    {
        super(type);

        this.videoResult=videoResult;

    }
    public override function clone():Event {
        return new YouTubeSearchEvent(this.type, this.videoResult);
    }
}

}

我AP preciate任何帮助。

I appreciate any help..

推荐答案

没有看到实际的自定义事件类使它有点难以看到那里的错误所在,但我猜你可能忘记了覆盖clone()方法

Not seeing your actual custom event class makes it a bit hard to see where the error lies, but I guess you might have forgotten to override the clone() method:

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html#clone%28%29

在创建自己的自定义Event类时,必须覆盖继承的Event.clone(),以便它复制自定义类的属性方法。如果你不将所有您在事件中添加属性子类,这些属性将不会有正确的值当侦听器处理重新调度的事件。

"When creating your own custom Event class, you must override the inherited Event.clone() method in order for it to duplicate the properties of your custom class. If you do not set all the properties that you add in your event subclass, those properties will not have the correct values when listeners handle the redispatched event."

这篇关于AS3传递自定义事件数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 03:42