Skip to content
November 28, 2011 / Danii Oliver

Flash SWFs Chatting it up with each other

Nick Versus Interactive Book & Touch Screen Application

This is code to test communication between two swfs where a Child swf has been loaded in to a parent or shell swf. 
The objective of the code is for the child swf to dispatch and event that the parent executes.
Please Note* there is actual code and there is test/debug code only in this code snippet test/debug code is removed in final execution of program.  

IN PARENT SWF

public function loadComplete(e:Event)
{
_page = MovieClip(l.content);
_page.addEventListener("removeUI",removeUI);
_page.sayHello();
_page.showMsg('What Page # are You?');
_page.returnSum(0)
trace(l.content.hasEventListener("removeUI"));
}

plus:

public function removeUI(e:Event= null):void
{
story.y=storyHide;
navBar.y=-900;
trace("removing UI");
trace('Gotta wait to advance!');
_page.removeEventListener("removeUI",removeUI);
_page.addEventListener("addUI",addUI);
}


IN CHILD SWF

in constructor because
((*EVENTS HAVE TO BE CALLED BY AN EVENT TO BE DISPATCHED*))
add:
this.addEventListener(Event.ENTER_FRAME, hideUI);
then: write the dispatch event callers, don’t forget to remove listeners

public function hideUI(e:Event= null):void
{
this.removeEventListener(Event.ENTER_FRAME, hideUI);
this.dispatchEvent(new Event("removeUI"));
}
public function showUI(e:Event = null):void
{
this.dispatchEvent(new Event("addUI"));
}

//==Testing for Communication=====Remove when dispatch is working to satisfaction==========================

public function sayHello ():void
{
trace('#######' + 'Hello, I am Page 0!');
}
public function showMsg(msg:String =""):void
{
trace('You said, ' + msg + " I am 0");
}
public function returnSum(num:Number=0):Number
{
return (num + 1);
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: