【发布时间】:2010-08-09 09:37:26
【问题描述】:
我正在尝试将自定义事件数据从一个类传递到另一个类...这是我的代码..
a.as
private function onClick(event:MouseEvent):void{
dispatchEvent(new YouTubeSearchEvent(YouTubeSearchEvent.CHANGE_VIDEO_READY, videoId));
}
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
// 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);
}
}
}
感谢您的帮助..
【问题讨论】:
-
如果您发布完整的课程定义会更容易帮助您...
-
我现在明白了....我只需要在我的自定义事件中使用 bubble=true...
标签: apache-flex flash actionscript-3