यदि आप किसी ईवेंट के माध्यम से ऑब्जेक्ट पास करना चाहते हैं तो आपको एक कस्टम ईवेंट बनाना चाहिए। कोड इस तरह कुछ होना चाहिए।
public class MyEvent extends Event
{
public static const GOT_RESULT:String = "gotResult";
// this is the object you want to pass through your event.
public var result:Object;
public function MyEvent(type:String, result:Object, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
this.result = result;
}
// always create a clone() method for events in case you want to redispatch them.
public override function clone():Event
{
return new MyEvent(type, result, bubbles, cancelable);
}
}
तो फिर तुम इस तरह से ऊपर कोड का उपयोग कर सकते हैं:
dispatchEvent(new MyEvent(MyEvent.GOT_RESULT, result));
और आप इस घटना को जहां आवश्यक के लिए सुन।
addEventListener(MyEvent.GOT_RESULT, myEventHandler);
// more code to follow here...
protected function myEventHandler(event:MyEvent):void
{
var myResult:Object = event.result; // this is how you use the event's property.
}
स्रोत
2012-09-25 20:08:48
आप एक उदाहरण अपने आप को दे दी है। आप वास्तव में कहाँ अटक गए हैं? – bfavaretto
उत्तर के लिए धन्यवाद, मैं as3 के लिए नया हूं और जानना चाहता हूं कि प्रेषण ईवेंट के साथ ऑब्जेक्ट को कैसे पास किया जाए? – user1022521
आपको अपनी खुद की कस्टम इवेंट ऑब्जेक्ट बनाने के लिए इवेंट क्लास का विस्तार करना होगा। यहां एक उदाहरण देखें: http://cookbooks.adobe.com/post_AS3__Creating_and_dispatching_Custom_Events-17609.html – bfavaretto