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: Sequential - A PureMVC / AS3 Demo  (Read 18713 times)
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« on: November 12, 2008, 06:56:21 »

This demo illustrates the use of the AsyncCommand utility to execute a series of commands, some of which must complete asynchronous operations before the next command can be executed.

The demo has historically been located here: http://trac.puremvc.org/Demo_AS3_Sequential
The project has been moved here: https://github.com/PureMVC/puremvc-as3-demo-flash-sequential/wiki

Standard and MultiCore versions are included.

The author is Duncan Hall.
« Last Edit: September 23, 2012, 12:44:19 by puremvc » Logged
Ohm
Newbie
*
Posts: 6


View Profile Email
« Reply #1 on: December 23, 2008, 06:01:49 »

Hello,

I'm tryin' to do this demo with Flex... :

OutputComponent.mxml :

:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" width="400" height="300"
title="PureMVC AsyncCommand" creationPolicy="all">

<mx:Script>
<![CDATA[

private var logCount:int = 1;

public function log( msg:String ):void
{
if ( ta_output == null ) return;
else ta_output.text += String( logCount )+ ". " + msg + "\n";
//output.text = String( logCount )+ ". " + msg + "\n";
logCount++;
}
]]>
</mx:Script>
<mx:TextArea id="ta_output" width="100%" height="100%"/>

</mx:Panel>

and my OutputMediator.as :
:
package org.view
{
import org.ApplicationFacade;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.mediator.Mediator;
import org.view.comp.OutputComponent;

public class OutputMediator extends Mediator
{
public static const NAME:String = "OutputMediator";

public function OutputMediator( viewComponent:OutputComponent )
{
trace("viewComponent: "+viewComponent.ta_output);
super( NAME, viewComponent );
}

// Called by the View when the Mediator is registered
override public function onRegister():void
{
sendNotification( ApplicationFacade.BEGIN_ASYNC_COMMANDS );
}

// List the INotification names this Mediator is interested in being notified of.
override public function listNotificationInterests():Array
{
return [ ApplicationFacade.LOG_OUTPUT ];
}

// Handle INotifications.
override public function handleNotification( notification:INotification ):void
{
switch ( notification.getName() )
{
case ApplicationFacade.LOG_OUTPUT:
var logMessage:String = notification.getBody() as String;
trace("logMessage: "+ logMessage);
output.log( logMessage );
break;
}
}

public function get output():OutputComponent
{
return viewComponent as OutputComponent;
}
}
}

the thing is that my output textarea (ta_output) is null at the moment of the first async command...???
I don't understand why and can't figure out the reason...
this is not the first time I try to port a demo for flash to flex and I always have this same problem of null object...
so this time I tried the simplest demo I found, but still have this annoying thing :-(

Would you please have any idea about this issue ?
Thx for help.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: December 23, 2008, 06:19:59 »

Without seeing the rest of the cod it would be quite difficult to say what is wrong, though I'd venture a guess its timing. the mxml application needs to have completely rendered by the time you startup the puremvc
apparatus. What can you tell us about your startup process
?
-=Cliff>
Logged
Ohm
Newbie
*
Posts: 6


View Profile Email
« Reply #3 on: December 23, 2008, 06:39:54 »

here is the main file "Sequential.mxml", and for the other files the code is the same than in the demo...

:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" >
<mx:Script>
<![CDATA[
import org.ApplicationFacade;
import org.view.comp.OutputComponent;

private function init():void
{
var facade:ApplicationFacade = ApplicationFacade.getInstance();
facade.startup( this );
}

public function set outputComponent( output:OutputComponent ):void
{
this.addChild( output );
}
]]>
</mx:Script>
<mx:Button label="Call AsyncCommand" click="init()"/>

</mx:Application>
Logged
Ohm
Newbie
*
Posts: 6


View Profile Email
« Reply #4 on: December 23, 2008, 07:50:13 »

Here is the whole stuff...
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: December 23, 2008, 08:17:04 »

Try this:

:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
   xmlns:mx="http://www.adobe.com/2006/mxml"
   xmlns:comp="org.view.comp.*"
   creationComplete="facade.startup(this)">

<mx:Script>
   <![CDATA[

   import org.ApplicationFacade;
   var facade:ApplicationFacade = ApplicationFacade.getInstance();

   ]]>
</mx:Script>

<comp:OutputComponent id="outputComp"/>

</mx:Application>


And in ApplicationMediator:

:
override public function onRegister():void
{
facade.registerMediator( new OutputMediator(app.OutputComp) );
}

-=Cliff>
« Last Edit: December 23, 2008, 08:28:48 by puremvc » Logged
Ohm
Newbie
*
Posts: 6


View Profile Email
« Reply #6 on: December 23, 2008, 09:03:17 »

Ok, thx Cliff !

works great  :)

I guess the trick was to register the comp (mediator) in the onRegister() function of the ApplicationMediator...  ::)

have a nice day.

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



View Profile WWW Email
« Reply #7 on: December 23, 2008, 04:57:18 »

... and rather than have the ApplicationMediator create the OutputComponent and inject it into the app, we just let the normal Flex creation process handle that by defining it as an MXML tag.

That way we know it exists when the app's creationComplete is fired, and the normal process of wrapping mediators around existing components can take place.

-=Cliff>
Logged
vipinck
Newbie
*
Posts: 1


View Profile Email
« Reply #8 on: March 11, 2009, 11:17:52 »

Cliff>>
This is nice utility where I can run my series of startup checks and updates for my AIR app. But there can be a commandError() function, which says the command failed and my micro-command can have setting like abortOnFailure..? My micro-command will fail and stop at a command which fails. I was thinking like this because all my async commands are kind of related to the next. If one fails, others doesn't make sense to run... Something like this will be possible?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #9 on: March 13, 2009, 07:41:25 »

I'm not sure that this utility will be optimal for this sort of thing because even if the subcommand can report failure there's not a lot of room for the AsyncMacroCommand to respond intelligently about what to do next.

I've recently used the StateMachine utility along with normal commands for a much more controllable startup process when the startup can spiral off into various sub processes conditionally.

In my AIR app I need to make sure I'm online or branch to an offline state until internet is detected again. Then I veed to check for updates and branch to a different process there if so. I need to verify your license or spiral into capture and save of that data before trying to valitate again. I need to verify and possibly capture and store S3 credentials in the same manner, all before registering proxies that retrieve data from the cloud and present it.

By defining all that as a set of discrete states (i.e. LICENSE_CHECKING, LICENSE_ENTRY,
LICENSE_SAVING...) And the actions that push the machine frome one state to the next, I was able to easily handle the conditional branching nature of the steps and progress smoothly through all States in a reliable way.

-=Cliff>
Logged
Pages: [1]
Print