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 [2] 3 4 ... 6
16  PureMVC Manifold / MultiCore Version / PureFormSubmission - Deferred Instantiation, StateMachine on: June 17, 2009, 12:12:36
While trying to understand the StateMachine I've followed the instructions on PureMVC TV
( http://puremvc.tv/ )
and made a (very simple) FormSubmission application.
The app is also illustrating my experimenting with the deferred instantiation and the registration of puremvc mediators.
It is not a demo, so it is not commented at all.
There are 3 Views containing form-fields.(One, SubOne, SubTwo)
The data will be collected from all 3 forms when the user presses the submit button..

Feedback from the puremvc gurus, experts or anyone else would be much appreciated, especially because I'm still in the process of learning how to use the StateMachine  and therefore I need   suggestions for better solutions.

http://sites.google.com/site/mvc4flex/Home/pureformsubmission
PureFormSubmission.swf  (demo)
PureFormSubmission.zip  (source)
http://code.google.com/p/ondina-air-flex-pmvc/source/checkout (source)

Ondina
17  Announcements and General Discussion / General Discussion / PureMVC TV on: June 11, 2009, 02:12:54
It might be a good habit for the users of this forum to take a look at  the “Home” (http://puremvc.org/component/option,com_frontpage/Itemid,1/) section of this website from time to time. There you can find interesting and useful announcements and info, such as the one about  the http://www.puremvc.tv/  project.

Cliff, I don't know which word to use to better describe that project and its future capabilities. I could just say: GREAT. But it wouldn't be enough, so I suggest you think of all the positive(good) superlatives, and  all of them would do a good job in describing the content and the value of the project.
I'm very impressed and thankful.

Ondina
18  Announcements and General Discussion / General Discussion / Re: Flex Code Formatter on: June 07, 2009, 02:40:08
Hey Jason,
Thanks for   the  tip.
I’ve just installed the Flex Formatter.  Very cool features!  Especially  the mxml options .
The  formatting of actionscript code works fine inside of  actionscript files and classes, but I can’t make it work inside of a Script tag.
Ondina
EDIT:I’ve tried Flex Formatter with Adobe Flash Builder 4. In FlexBuilder 3 it works fine inside of a <mx:Script></mx:Script>  tag.
The problem seems to be  the new  fx prefix. Obviously  Flex Formatter  doesn’t recognize  the <fx:Script> . Actually something to be reported on their forum, if I wasn’t so lazy.
Anyway I’m wondering how the Fx-prefix and the new namespaces will affect the porting of my apps from Flex3 to Flex4  FlashBuilder4…

19  Announcements and General Discussion / General Discussion / Re: dispatch MouseEvent from view component on: May 19, 2009, 08:52:47
But just to be a bore..., adding the eventListener like this

mediatorComponent.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, false, 0, true);

would lead to handling every MouseEvent in the view.
Right?

As for the bubbling from an image-click you are right.

Again, perhaps I was mislead by the example he gave and he does indeed need custom event names
Yes it's hard to say from just a fragment of code.
Well, we both tried to help  :)

Ondina
20  Announcements and General Discussion / General Discussion / Re: dispatch MouseEvent from view component on: May 19, 2009, 07:28:54
No, Jason, you are not missing anything :)

There was an event type coercion error(Event->MouseEvent) and I meant to say that a  flash.events.Event cannot be handled as a flash.events.MouseEvent.

I'm sorry for the misleading :
dispatchEvent( new MouseEvent( eventName, true ) );

The idea was that you should dispatch the event that your handler-method can handle. I didn't mean to say that you have to recreate the event. Sorry for that.

But in your example how would you add an eventListener in the mediator, if you don't define a type for the event in your view?

Maybe like this?
public static const IMG_CLICKED:String = 'imageClicked';

<mx:Image source="{rp.currentItem}" buttonMode="true" width="60" height="60" click="dispatchEvent(new Event(IMG_CLICKED, true))" />

(bubbles=true)

Ondina
21  Announcements and General Discussion / Architecture / Re: Pipes and the StateMachine Walkthrough on: May 19, 2009, 12:52:40
Thank you Joel!
Your addition to Cliff's demo has great didactic value.

Ondina.
22  Announcements and General Discussion / General Discussion / Re: dispatch MouseEvent from view component on: May 19, 2009, 12:31:12
First of all, even if that's not the cause of your problem, it's a good practice not to use  event's types that could cause a name collision with the generic  flex/flash events (click, change,  add, initialize.. e.t.c.)

Then I would suggest that you take a look at your mediator again.
There you probably have something like this:
override public function onRegister( ):void
{
myView.addEventListener( MyView.CLICK, onImageClick );
}
private function onImageClick ( event: MouseEvent ): void
{
//do something
}

You have to change it to event:Event because the  MyView.CLICK isn't a MouseEvent.

But if you have to keep “MouseEvent” as the event type in your mediator's event-handler, you can do this in your view to make it work:

private function sendEvent( eventName:String ):void
{
dispatchEvent( new MouseEvent( eventName, true ) );
}

Ondina
23  Announcements and General Discussion / Public Demos, Tools and Applications / Re: New Open-Source Flash/Flex CMS, need advice on Structure on: May 17, 2009, 01:25:52
That's an interesting integration of  frameworks.
Your incipient project looks promising.
I'm into everything related to Flex+puremvc+Zend-AMF, so I'll be keeping an eye on your project ;)
Keep it up!
Ondina
24  Announcements and General Discussion / General Discussion / Wolfram|Alpha on: May 16, 2009, 12:50:06
“Wolfram|Alpha just went live for the very first time, running all clusters.”
http://www.wolframalpha.com/

I thought that someone who is interested in design patterns might as well want to know about WolframAlpha, the answer-engine.
It doesn't know anything about pureMVC yet ...:)

Ondina
25  Announcements and General Discussion / Public Demos, Tools and Applications / Re: New application - a tribute to PureMVC on: May 07, 2009, 10:07:23
Interesting application. Very nice design and layout!
Since I'm working with AIR & Zend-AMF & MySQL, I'm for sure interested in the topic.

A guest account for puremvc users would be nice ( without the email stuff).

Cheers,
Ondina
26  PureMVC Manifold / Demos and Utils / Re: StateMachine - A PureMVC / AS3 Utility on: May 07, 2009, 05:13:51
@Cliff

Hmm... you know what? Your demo is not good at all. It distracted me from my goal (learning more about StateMachine). It made me listen to the cool sound tracks and after a while my mind entered in a state of not caring anymore about FSM&Co  :)

O.K.  Back to the earthy state... Thank you for the much awaited demo! I'll come back with questions after trying it.

One little observation, not related to puremvc:
I have an external sound card, that was off by the time I started your demo and that made the app throw an error when I was  trying to select an item. Maybe you should catch this(sound off) somewhere in your code.


@Simon

I'll post my questions regarding your demo in here instead of your blog.

Here the FSM:
var fsm:XML =
<fsm initial={StateConstants.LOAD}>
<state name={StateConstants.LOAD}>
<transition action={ActionConstants.ACTION_LOAD} target={StateConstants.LOGIN}/>
</state>
<state name={StateConstants.LOGIN} exiting={ ApplicationFacade.CHECK_LOGGED_IN }>
<transition action={ActionConstants.ACTION_USER} target={StateConstants.STATE_2}/>
<transition action={ActionConstants.ACTION_ADMIN} target={StateConstants.STATE_3}/>
</state>
<state name={StateConstants.STATE_2} changed={ ApplicationFacade.CHECK_LOGGED_IN }>
<transition action={ActionConstants.ACTION_LOGIN} target={StateConstants.LOGIN}/>
<transition action={ActionConstants.ACTION_THREE} target={StateConstants.STATE_3}/>
</state>
<state name={StateConstants.STATE_3} changed={ ApplicationFacade.CHECK_LOGGED_IN } entering={ ApplicationFacade.CHECK_ADMIN }>
<transition action={ActionConstants.ACTION_LOGIN} target={StateConstants.LOGIN}/>
<transition action={ActionConstants.ACTION_TWO} target={StateConstants.STATE_2}/>
</state>
</fsm>;

1.Why do you need  changed={ ApplicationFacade.CHECK_LOGGED_IN }  in state 2 and 3? You  can be in those states only after a successfully login, right?
2.Then in the LOGIN state I expected it to do something in case the password/username was wrong, because in your CheckLoginStatusCommand you have this:
override public function execute(notification:INotification):void
{
      if( !lgnPrx.login_success ) sendNotification( StateMachine.ACTION, null, ActionConstants.ACTION_LOGIN );
}
I modified it to see what was going on:
if( !lgnPrx.login_success ){
   Alert.show("wrong pw");
   sendNotification( StateMachine.ACTION, null, ActionConstants.ACTION_LOGIN );
} else{
   Alert.show("Hi "+lgnPrx.username);
}
And if login_success==true  then it does say “Hi username”, after logging in.
It is actually normal, because it happens only  on exiting the LOGIN state.
So sendNotification( StateMachine.ACTION, null, ActionConstants.ACTION_LOGIN ); is not doing anything.
Was your intention to cancel the transition to the next state?


The cool thing is: entering={ ApplicationFacade.CHECK_ADMIN }, because I can do something like this:

CheckAdminStatusCommand
...
if( !lgnPrx.userAdmin ) {
sendNotification( StateMachine.CANCEL );
Alert.show("you are not admin");
}
...
when the user with restricted access clicks on the admin button.

Thank you  Cliff, Simon, Neil, gjstrab  for your demos and explanations/posts.

Ondina
27  PureMVC Manifold / Standard Version / Re: Every view component can be linked to a Mediator? on: April 25, 2009, 03:51:32
And here is how I actually use it in my current project:

TwoView.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:views="com.view.component.*"
creationComplete="addMyListeners()">
   <mx:Script>
   <![CDATA[
      import mx.events.FlexEvent;
      
      public static const SECOND_STACK:String   = 'SecondStack';
      
      public var activeView:Object =  new Object();
      public var numberOfViews:uint = 0;
      public var visitedViews:uint = 0;
      
      private function sendEvent( event:Event ):void{
         dispatchEvent( new Event( SECOND_STACK , true ) );
      }
      private function setFirstView( event:Event ):void{
         activeView = secondViewStack.selectedChild;
      }
      private function addMyListeners():void{
         numberOfViews = secondViewStack.numChildren;
         for (var i:uint=0; i<numberOfViews; i++){
            secondViewStack.getChildAt(i).addEventListener( FlexEvent.CREATION_COMPLETE, sendEvent );
         }
      }
      public function removeMyListeners():void{
         for (var i:uint=0; i<numberOfViews; i++){
            secondViewStack.getChildAt(i).removeEventListener( FlexEvent.CREATION_COMPLETE, sendEvent );
         }
      }
   ]]>
   </mx:Script>
   <mx:Binding source="secondViewStack.selectedChild" destination="activeView"/>
   <mx:TabBar id="secondTabBar" dataProvider="{secondViewStack}" styleName="secondTabBar" top="5" left="80"/>
   <mx:ViewStack id="secondViewStack" childAdd="setFirstView(event)" top="30" left="80" width="70%" height="90%" >
      <views:SubOneView label="SubOne" id="SubOneView"/>
      <views:SubTwoView label="SubTwo" id="SubTwoView"/>
      <views:SubThreeView label="SubThree" id="SubThreeView"/>   
   </mx:ViewStack>
</mx:Canvas>

TwoViewMediator.as
package com.view.mediator
{
   import com.view.component.TwoView;
   
   import flash.events.Event;
   
   import org.puremvc.as3.multicore.interfaces.IMediator;
   import org.puremvc.as3.multicore.patterns.mediator.Mediator;
   
   public class TwoViewMediator extends Mediator implements IMediator
   {
      public static const NAME:String = 'TwoViewMediator';
      
      public function TwoViewMediator( viewComponent: Object )
      {
         super( NAME, viewComponent );
      }
      protected function get twoView(): TwoView
      {
         return viewComponent as TwoView;
      }
      override public function onRegister():void
      {
         twoView.addEventListener( TwoView.SECOND_STACK, onViewCreated );
         checkForMediator( twoView.activeView );
      }
      protected function onViewCreated( event:Event ):void
      {
         checkForMediator( twoView.activeView );
      }
      protected function checkForMediator( child:Object ):void
      {
         twoView.visitedViews++;
         switch ( child.id )
         {
            case "SubOneView":
               if ( ! facade.hasMediator( SubOneViewMediator.NAME ) )
               facade.registerMediator(new SubOneViewMediator( child ));
            break;
            case "SubTwoView":
               if ( ! facade.hasMediator( SubTwoViewMediator.NAME ) )
               facade.registerMediator(new SubTwoViewMediator( child ));
            break;
            case "SubThreeView":
               if ( ! facade.hasMediator( SubThreeViewMediator.NAME ) )
               facade.registerMediator(new SubThreeViewMediator( child ));
            break;    
         }
         if(twoView.visitedViews==twoView.numberOfViews){
            twoView.removeEventListener( TwoView.SECOND_STACK, onViewCreated );
            twoView.removeMyListeners();
         }
      }       
   }
}

I would like to hear a suggestion for a better approach or other ways of doing this.
Is it bad not to use constants for every View, that dispatches an event on creationComplete? Maybe I can't see the bad consequences of it.
The way I handle this allows me to change the Views' order without having to change the constants or anything else. And also I have fewer constants in the View and Mediator.

Ondina
28  PureMVC Manifold / Standard Version / Re: Every view component can be linked to a Mediator? on: April 22, 2009, 10:52:26
It seems, that the issue of deferred instantiation in Flex and the way puremvc registers the mediators, is something that almost every beginner has to deal with.

The Slacker Demo is indeed the answer to this dilemma.

But there is a slight difference between the Slacker Demo and how many developers build their navigation.
In the Slacker Demo you have to have a SplashView in order to get it work.
The SplashView doesn't have a Mediator.

But not always is it possible to have such a View without a Mediator.

For my project I needed a TabBar + ViewStack to navigate through the views.
In fact I have nested ViewStacks.
I have a MainView that contains the ViewStack and a MainViewMediator.
I register the mediator for the first view of the stack in the onRegister()method of the MainViewMediator. It works.

I thought, maybe it could help someone to see how I did it.
It is something I did when I started with puremvc, so there are imperfections there!
Especially there is an unorthodox way of getting the views' names when I register their mediators, but I had a good reason for doing so. Cliff will chide me for this!! And you should do it like in the SlackerDemo not like I did it.

I wanted to attach the example, but attachments are no longer allowed. So I'll post parts of it in here.

I hope it will help someone.

MainView
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:views="com.view.component.*" >
<mx:Script>
<![CDATA[
public static const TWO_CREATED:String       = 'twoViewCreated';
public static const THREE_CREATED:String    = 'threeViewCreated';

public var activeView:Object;

private function sendEvent(event:Event, action:String ):void{
activeView = event.currentTarget;
dispatchEvent(new Event( action, true ));
}
private function setActiveView(event:Event):void{
activeView = event.currentTarget.getChildAt(0);
}
]]>
</mx:Script>
<mx:TabBar id="mainTabBar" dataProvider="{mainViewStack}" />
<mx:ViewStack id="mainViewStack" childAdd="setActiveView(event)">
<views:OneView label="One" id="OneView"/>
<views:TwoView label="Two" id="TwoView" creationComplete="sendEvent(event, TWO_CREATED)"/>
<views:ThreeView label="Three" id="ThreeView" creationComplete="sendEvent(event, THREE_CREATED);"/>
</mx:ViewStack>
</mx:Canvas>


MainViewMediator
package com.view.mediator
{
   import com.view.component.MainView;
   
   import flash.events.Event;
   
   import org.puremvc.as3.multicore.interfaces.IMediator;
   import org.puremvc.as3.multicore.patterns.mediator.Mediator;

   public class MainViewMediator extends Mediator implements IMediator
   {
      public static const NAME:String = 'MainViewMediator';
      
      public function MainViewMediator(viewComponent: MainView)
      {
         super(NAME, viewComponent);
      }
      protected function get mainView(): MainView
      {
         return viewComponent as MainView;
      }
      override public function onRegister( ):void
      {
         mainView.addEventListener( MainView.TWO_CREATED, onViewsCreated );
         mainView.addEventListener( MainView.THREE_CREATED, onViewsCreated );
         //HERE IS THE TRICK: register the mediator for the first view in the stack
         checkForMediator( mainView.activeView );
      }
      protected function onViewsCreated( event:Event ):void
      {
         checkForMediator( mainView.activeView );
         //checkForMediator( event.currentTarget.activeView );
      }
      protected function checkForMediator(  child:Object ):void
      {
         switch ( child.id )
         {
            case "OneView":
               if ( ! facade.hasMediator( OneViewMediator.NAME ) )
               facade.registerMediator(new OneViewMediator( child ));
            break;
            case "TwoView":
               if ( ! facade.hasMediator( TwoViewMediator.NAME ) )
               facade.registerMediator(new TwoViewMediator( child ));
            break;
            case "ThreeView":
               if ( ! facade.hasMediator( ThreeViewMediator.NAME ) )
               facade.registerMediator(new ThreeViewMediator( child ));
            break;
         }
      }       
   }
}

The second View has also a TabBar and a ViewStack, but the post would be too long if I posted the entire code.

Ondina
29  Announcements and General Discussion / General Discussion / Re: SQLite compound INSERT on: April 21, 2009, 12:23:56
My first thought about your question was: why don't you use transactions?

My guess is that your SQLite Admin (which one are you using?) is grouping your statements  into a  transaction.
It probably makes an array out of your statements and loops through them inside a transaction.
That's probably why your “long query” works in there.

If you simply add a statement after another and try to execute() them all together it wont work, because, as far as I know, only one statement is executed at a time. I would suggest you use transactions.

Right now i have to loop thru each insert with a new sql class and connection per one.
Unfortunately, after about 430 records, it stops.

Can you say more about this?  Are you inserting the records into the same table, or are there different tables? Were you using asynchronous or synchronous connections?

Ondina
30  Announcements and General Discussion / General Discussion / Re: DesktopCitizen and Main Window's visibilty on: April 16, 2009, 11:51:09
Now that I'm reading your first post again, I see your “real” problem, or so I think.

You set WindowedApplication visible=false.
Then on applicationComplete you initialized the PureMVC apparatus:
Facade, ApplicationMediator, DesktopCitizenMediator

Your additional window is created and opened in the ApplicationMediator and you expect the  WindowedApplication to not be visible until the added window has finished its work.

But the DesktopCitizenMediator has already set the
stage.nativeWindow.visible = true; when handling the notification WINDOW_SHOW

and that happened before you created your additional window.

That's why you see the  WindowedApplication for a short while.

You have to put
sendNotification( DesktopCitizenConstants.WINDOW_OPEN, app.stage );

there where you consider that your additional window has finished its work or where you wanted your  WindowedApplication to be visible again.

It will work!

Ondina
Pages: 1 [2] 3 4 ... 6