Skip to main content
March 25, 2011
Question

Unable to get custom events from child movie clip

  • March 25, 2011
  • 1 reply
  • 305 views

Hey Guys

I am not much aware of AS 2.0 and i am stuck at getting custom events from Child SWF to Parent SWF file

Please find my code attched.

Any sort of help would be great...

Thanks a lot man!!!

Parent swf

System.security.allowDomain("*");

import mx.utils.Delegate;

var addEventListener:Function;

createEmptyMovieClip("mcTemp",this.getNextHighestDepth());

var loader:MovieClipLoader = new MovieClipLoader();

loader.addListener(this);

loader.loadClip("EventDispatcher.swf", mcTemp);

var eventHandlerDelegate = Delegate.create(this, eventHandler);

function onLoadComplete(e):Void

{

trace("on load complete");

mcTemp.onPlay();

mcTemp.addEventListener("hello", this);

mcTemp.addEventListener("onPickedUp", this);

mcTemp.addEventListener("onDropped", this);

mcTemp.addEventListener("END_OF_QUIZ", this);

}

function onPickedUp(e:Object)

{

trace("11111111111onPickedUp");

}

function onDropped(e:Object)

{

trace("onDropped");

}

function hello(e:Object)

{

trace("hello");

}

*********************************************************End********************************************
Child :
stop();
import mx.events.EventDispatcher;
var broadcaster:Object = new Object();
EventDispatcher.initialize(broadcaster);
var listener:Object = new Object();
listener.onPickedUp = function() {
this.dispatchEvent({type:"onPickedUp"});
trace("Picked up.");
};
listener.onDropped = function(evt:Object) {
trace("Dropped on " + evt.msg + " side.");
};
broadcaster.addEventListener("onPickedUp", listener);
broadcaster.addEventListener("onDropped", listener);
// ** General code **
var halfway:Number = Stage.width / 2;
mcBall.onPress = function() {
this.startDrag();
broadcaster.dispatchEvent({type:"onPickedUp"});
};
mcBall.onRelease = function() {
this.stopDrag();
if (this._x < halfway) {
broadcaster.dispatchEvent({type:"onDropped", msg:"left"});
} else {
broadcaster.dispatchEvent({type:"onDropped", msg:"right"});
}
};
function onPlay()
{
flash.external.ExternalInterface.call("alert", "inside onPlay");
trace("inside player");
}

This topic has been closed for replies.

1 reply

March 26, 2011

Every one.. Thanks for spending some time on this... I have got it resolved...

There were two problems with my code...

1. The eventlistener should have been added inside the onLoadInit function of the Container SWF

2. In the child swf i should have done EventDispatcher.initialize(this); instead of initializing the "broadcaster".

Thanks