Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Different SWF communicating with LocalConnection and Pipes?  (Read 4749 times)
Bill_BSB
Jr. Member
**
Posts: 13


View Profile Email
« on: September 05, 2008, 03:15:22 »

Hi guys,

one of the great things of building applications is the opportunity to put in practice great ideas that solve great problems.

And I´m in the edge of solving a simple problem: How to make two PureMVC MultiCore-Pipes applications in different SWFs  communicate.

I hope you guys can help me.

One Swf is the Shell and the other is operating as Module but in fact it is a <mx:Application> that implements IPipeAwareModule and all other PMVCMCP classes for regular modules. The Shell loads the external SWF and cast it as local ExternalModule that implements IPipeAwareModule.

Something similar as
:
public class ExternalModule extends UIComponent implements IPipeAwareModule{

private var _request:URLRequest;
private var _loader:Loader;
private var _url:String;
private var _conn:LocalConnection;

public function ExternalModule ()
{
_request = new URLRequest(url);
_loader = new Loader();

_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);

_loader.contentLoaderInfo.addEventListener(FaultEvent.FAULT, onFault);

_conn = new LocalConnection();

_conn.allowDomain();

_conn.addEventListener(StatusEvent.STATUS, onStatus);

                _conn.client = this;
}

               public function load():void{
CursorManager.setBusyCursor();
try{
_loader.load(_request);
}
catch (error:Error)
                       {
                           CursorManager.removeBusyCursor();
                              trace("Unable to load URL: " + error);
                        }
        }

                private function onLoaded(evt:Event):void{
CursorManager.removeBusyCursor();

// Loader can be added to the UIComponent class. ???
addChild(_loader);

try
{
// listen to events from child
    _conn.connect("fromChild");
}
catch (error:ArgumentError)
{
    trace("Error:"+error.message);
}

// Inform everything went just fine.
dispatchEvent(new AddModuleEvent(this as DisplayObject) );
}

                public function acceptInputPipe( name:String, pipe:IPipeFitting ):void
{
// try to execute in the external SWF
_conn.send("fromParent","acceptInputPipe",name,pipe);
}

public function acceptOutputPipe( name:String, pipe:IPipeFitting ):void
{
// try to execute in the external SWF
_conn.send("fromParent","acceptOutputPipe",name,pipe);
}

public function garbageCollection():void
{
//dispatchEvent( new Event( COLLECT_GARBAGE ) );
}

private function onStatus(event:StatusEvent):void {
switch (event.level) {
case "status":
trace(event.toString());
break;

case "error":
trace(event);
break;
}
}
}

And on the external SWF something like this:
:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
implements="com.common.IPipeAwareModule" initialize="initializeHandler(event)">

<mx:Script>
<![CDATA[
import org.osflash.thunderbolt.Logger;
import org.puremvc.as3.multicore.utilities.pipes.plumbing.JunctionMediator;
import mx.events.FlexEvent;
import com.mapmodule.ApplicationFacade;
import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeFitting;

public static const NAME:String = 'MapModule';

private var facade:ApplicationFacade = ApplicationFacade.getInstance(NAME);

private var _facade: ApplicationFacade;

private var _conn:LocalConnection;

private function initializeHandler(event: FlexEvent):void
{

_facade = ApplicationFacade.getInstance( NAME );
_facade.startup( this );

_conn = new LocalConnection();
_conn.allowDomain();
_conn.client = this;

try
{
Logger.debug("Tentando se conectar a fromParent...");
// listen to events from the parent
    _conn.connect("fromParent");
}
catch (error:ArgumentError)
{
    trace("Error:"+error.message);
}
}

public function acceptInputPipe( name:String, pipe:IPipeFitting ):void
{
Logger.debug(NAME+".acceptInputPipe");
_facade.sendNotification( JunctionMediator.ACCEPT_INPUT_PIPE, pipe, name );
}

public function acceptOutputPipe( name:String, pipe:IPipeFitting ):void
{
Logger.debug(NAME+".acceptOutputPipe");
_facade.sendNotification( JunctionMediator.ACCEPT_OUTPUT_PIPE, pipe, name );
}

public function dispose():void
{
_facade.sendNotification(ApplicationFacade.DISPOSE);
}
]]>
</mx:Script>
<mx:ViewStack id="vwsViewstack" creationPolicy="all" height="100%" width="100%">
<mx:Canvas height="100%" width="100%">
<mx:Text text="Carregando mapa ..." fontSize="16" color="#CFF1F8" fontWeight="bold" bottom="261" top="250" left="30" right="50"/>
</mx:Canvas>

<mx:Canvas height="100%" width="100%">
<mx:UIComponent id="mapLayer" width="100%" height="100%" />
</mx:Canvas>
</mx:ViewStack>
</mx:Application>


So, the main idea is to register the in/out pipes. But I´m getting some strange error on the onStatus(event:StatusEvent) that has no info, no code no nothing. The trace is:
[StatusEvent type="status" bubbles=false cancelable=false eventPhase=2 code=null level="error"].

And the Logger.debug(NAME+".acceptInputPipe"); in acceptInputPipe/acceptOutputPipe never executes.

And when I try to send a message from Shell to external Module (junction.sendMessage( PipeAwareModuleConstants.SHELL_TO_MODULE_PIPE, msg); )I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at org.puremvc.as3.multicore.utilities.pipes.plumbing::Pipe/write()[C:\eclipseWorkspace\Utility_AS3_MultiCore_Pipes\src\org\puremvc\as3\multicore\utilities\pipes\plumbing\Pipe.as:72]


That´s the general idea and the general error. Did you guys get it? If not, I can post more code here. I´m kinda messed here right now trying to solve this.

So please, tips appreciated!

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: September 05, 2008, 04:47:05 »

Your error in red should go away when you find out what your first error (status = error) is all about (i.e is it a flex related thing, or is it your module). I can't discern much more than that from what I see, other than to say you should use the debugger. Place a breakpoint in that onStatus method, run Flex Builder in debug mode and see what you can see. event.target should give you a reference to the object that sent the event. Also set some breakpoints as early into the other app as you can. Find out how far it gets before blowing up.

-=Cliff>
Logged
Pages: [1]
Print