Apache flex AS3传递自定义事件数据问题
我正在尝试将自定义事件数据从一个类传递到另一个类…这是我的代码 a、 作为 b、 作为 c、 作为Apache flex AS3传递自定义事件数据问题,apache-flex,flash,actionscript-3,Apache Flex,Flash,Actionscript 3,我正在尝试将自定义事件数据从一个类传递到另一个类…这是我的代码 a、 作为 b、 作为 c、 作为 // 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 create
// 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
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);
}
}
}
非常感谢您的帮助。如果看不到实际的自定义事件类,就有点难以看到错误所在,但我想您可能忘记重写clone()方法了:
创建自己的自定义事件类时,必须重写继承的Event.clone()方法,以便复制自定义类的属性。如果未设置添加到事件子类中的所有属性,则侦听器处理重新修补的事件时,这些属性的值将不正确看不到实际的自定义事件类使您很难看到错误所在,但我想您可能忘记重写clone()方法了:
创建自己的自定义事件类时,必须重写继承的Event.clone()方法,以便复制自定义类的属性。如果未设置添加到事件子类中的所有属性,则侦听器处理重新修补的事件时,这些属性的值将不正确您也可以这样发送活动:
var event:YouTubeSearchEvent = new YouTubeSearchEvent(YouTubeSearchEvent.CHANGE_VIDEO_READY);
event.videoId = theOneVideoId;
dispatchEvent(event);
您需要一个侦听器来注意事件是否被调度。
所以你需要像
searchContainer.addEventListener(YouTubeSearchEvent.CHANGE_VIDEO_READY,onChangeVideoReady);
如果事件现在已调度,则调用onChangeVideoReady(事件:YouTubeSearchEvent)方法。
您可以访问event.videoId
也许您可以看看框架,其中的事件也非常重要。您也可以这样发送事件:
var event:YouTubeSearchEvent = new YouTubeSearchEvent(YouTubeSearchEvent.CHANGE_VIDEO_READY);
event.videoId = theOneVideoId;
dispatchEvent(event);
您需要一个侦听器来注意事件是否被调度。
所以你需要像
searchContainer.addEventListener(YouTubeSearchEvent.CHANGE_VIDEO_READY,onChangeVideoReady);
如果事件现在已调度,则调用onChangeVideoReady(事件:YouTubeSearchEvent)方法。
您可以访问event.videoId
也许你可以看看框架,事件也非常重要。如果发布完整的类定义,将更容易帮助您…我现在就知道了…我只需要在自定义事件中为bubble=true…如果发布完整的类定义,将更容易帮助您…我现在就知道了…我只需要在自定义事件中为bubble=true…我刚刚在发帖…我已经一整晚没睡了…我的头现在不在了+1虽然我的猜测是正确的-在自定义事件中没有覆盖clone()方法。你应该试一试。公共重写函数clone():事件{返回新的YouTubeSearchEvent(this.type,this.videoResult);}我添加了你的覆盖方法,但仍然不走运……我的问题是我的c.as永远不会从a.as接收事件对象……只有b.as可以接收它……很好……我刚刚在帖子中更新了我的自定义事件……我已经一整晚没睡了……我的头现在不在了+1虽然我的猜测是正确的-在自定义事件中没有覆盖clone()方法。你应该试一试。公共重写函数clone():Event{return new YouTubeSearchEvent(this.type,this.videoResult);}我添加了你的重写方法,但仍然没有运气…我的问题是我的c.as永远不会从a.as接收事件对象…只有b.as可以接收它…weired。。。。