我想从1级传递自定义事件数据到其他类...这是我的代码..AS3传递自定义事件数据询问
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 { 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);
}
}
}
我感谢所有帮助..
如果你发布完整的课程定义,它会更容易帮助你... – OXMO456 2010-08-09 10:04:26
我现在得到了....我需要的是bubble = true在我的自定义事件中... – FlyingCat 2010-08-09 19:25:12