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

Show Posts

| * |

  Show Posts
Pages: [1]
1  PureMVC Manifold / MultiCore Version / FSM Utility Question on: December 18, 2008, 10:26:29
Hi guys,

I just started using the FMS utility, wich I think it´s a incredible utility, and I already got some questions.

I´m making a simple remote login app. The FMS xml is as follow

:
<fsm initial={App.STATE_READY}>
  <state name={App.STATE_READY} entering={LoginPanelMediator.RESET} exiting= LoginPanelMediator.LOGIN_TRY}>
    <transition action={LoginPanelMediator.VALID_LOGIN_FORM} target={App.STATE_TRY_LOGIN}/>
  </state>
   
  <state name={App.STATE_TRY_LOGIN} entering={ApplicationFacade.CMD_LOGIN}>
    <transition action={UserProxy.ACTION_LOGIN_OK} target={App.STATE_USER_HOME}/>
    <transition action={UserProxy.ACTION_LOGIN_FAIL} target={App.STATE_READY}/>
  </state>
   
  <state name={App.STATE_USER_HOME} >
    <transition action={App.ACTION_LOGOUT} target={App.STATE_READY}/>
  </state>    
</fsm>;

The idea is that simple: Initial state presents the Login Panel. When the user click on button "Log me in!" the app changes to the "Trying to Login" State that shows a wait message. The login is validated on a PHP remote server. If the response is a valid login, change the app state to the "User Home State" wich shows the user´s home screen. If not valid login, goes back to initial state showing the error message sent by the server. The only action that is avaiable on User Home state is the Logout wich brings the user back to the initial state of the app.

Well, that didn´t work as I expected. In fact, I found my self traped in a mase of notifications and actions and commands. And the timming and flow of them.

The problem was that the remote response was being faster that the FSM could change state. In detail: the UserProxy executes the login() method, the response is instantaneous, so it send the UserProxy.ACTION_LOGIN_* notification. But, the app is still in STATE_READY that doesn´t know how to process the action, so the app stops working.

To fix that, I just changed the StateMachine.as, transitionTo() method like this:
:
// Enter the next State
currentState = nextState;
if ( nextState.entering ) sendNotification( nextState.entering, nextState );
//currentState = nextState;

I don´t know if this right but ... what do you guys think? I really don´t feel confortable changing the Utilitys source but other fixes would need much more coding.

Looking foward for you solutions and comments.  :)
2  PureMVC Manifold / MultiCore Version / Different SWF communicating with LocalConnection and Pipes? 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!

Pages: [1]