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  Announcements and General Discussion / General Discussion / Re: Deferred Instantiation... Ughh! on: August 24, 2008, 03:33:28
I just confirmed it... when my mainScreen canvas' mediator is created, during onRegister() this.mainScreen.adminBtn == null, as is all other children..

Am I mistaken to assume that when the component's creationComplete event is fired shouldn't that mean that all the children were created as well?

John
2  Announcements and General Discussion / General Discussion / Re: Deferred Instantiation... Ughh! on: August 24, 2008, 01:28:41
Just an update:

I tried using onRegister() to register my event handlers and they are still null :(

MyComponent.mxml
:
<mx:Canvas>
   <mx:Button id="myBtn"/>
</mx:Canvas>

Main.mxml (abbr.)
:
<view:MyComponent id="myC" creationComplete="dispatchEvent(new Event("mycreated"));"/>

MainMediator.as (abbr.)
:
...
public function MainMediator(vc:Main)
{
       super(NAME, vc);
       
       (viewComponent as Main).addEventListener("mycreated", onComponentCreated);

       if((viewComponent as Main).myC)
             facade.registerMediator(new MyComponentMediator((viewComponent as Main).myC));
}

protected function onComponentCreated(e:Event):void
{
     if(!facade.hasMediator(MyComponentMediator.NAME))
     {
         facade.registerMediator(new MyComponentMediator((viewComponent as Main).myC));
     }
}

MyComponentMediator.as
:
...
override public function onRegister():void
{
      // THIS IS THE CODE WHERE I GET A NULL REFERENCE ON myBtn
      (viewComponent as MyComponent).myBtn.addEventListener(MouseEvent.CLICK, onMouseClick);
}

Note that I've expanded out the whole (viewComponent as foo) stuff, I know I could have created a getter to do that for me.. The problem you can see is that last code block, onRegister() blows up on trying to add an event listener to myBtn, because myBtn == NULL and I have no idea why..

Hopefully that helps..

John
3  Announcements and General Discussion / General Discussion / Re: Deferred Instantiation... Ughh! on: August 24, 2008, 12:59:11
Hey Cliff:

I understand the helper function to do my type casting, and I'm assuming the name of the variable in my constructor for the view object is not relevant, only what I pass to the parent's constructor via super()... The problem I am having is that, in that constructor, objects I would have expected to exist (viewComponent.myButton) are null references after the super(NAME, vc) call. I must have glossed over the notion of the onRegister() method in my readings so I'll take a second look at that and see if onRegister() solves my problem or not.. (the current problem being viewComponent.myButton in the Mediator's constructor is null).. To put it another way.. the component passed into my mediator's constructor exists, but it's children do not, which is very odd to me since the mediator's registration is triggered by the creationComplete event of the component, which I assume is called once the component creation is indeed complete..

Here is some more detail as well as a general AS3 / Flex question.. Consider this simple component code:

MyComponent.mxml
:
<mx:Canvas>
    <mx:Button id="myButton" creationComplete="dispatchEvent(new Event("Foo"))"/>
</mx:Canvas

Now.. in my "main app"

:
   <view:MyComponent creationComplete="facade.registerMediator();"/>

So what happens here is that the registerMediator() method will register the mediator for the MyComponent component but in the MyComponentMediator constructor (after the super() call) viewComponent.myButton is still null (this is my current problem)..

My question here though is this.. in the MXML document I was able to specify event handlers for what clearly are non-existent objects (as viewComponent.myButton is still null after the Canvas creationComplete event fires).. However, since they were statically defined at compile time the events must be bound to the object on-creation by Flex itself.. Surely this implies that Flex / AS3 has some sort of lookup table which stores the event handlers for non-existent objects until they are actually instantiated internally -- is there any way to access that mechanism at runtime to lazy-bind event handlers to not-yet-instantiated objects?


4  Announcements and General Discussion / General Discussion / Deferred Instantiation... Ughh! on: August 23, 2008, 06:34:52
Hey all,

So I'll be the first to admit that I'm fairly new to Flex and AS3 in general, but so far I've been doing pretty well and I've settled on PureMVC as the architecture we'd like to use for this project.. However, I'm finding myself in Deferred Instantiation hell and it's really bothering me..

Here's the basic problem:

Main app has a view stack with a bunch of Canvas components.. I've read all the FAQs and saw the Slacker demo and I get it.. I create a few custom events which trigger the ApplicationMediator to create whatever mediators I want when each component is actually created by AIR. Fair enough..

My problem is past that point..

So consider if I have a ViewStack with two views.. Splash and Main.. I need to fire an event on creation of Main to register it's mediator, but now what of my Main component's components? Although the creationComplete event fired, and now my mediator is registered all of the sub-components still don't exist so in the constructor of my MainMediator, where I'd like to register event handlers (for instance, to handle an click event from a button in my component) viewComponent.myButton is *still* null.. which means I in my new component again have to create all of these dummy events to fire and then capture the dummy events in the mediator to then call real methods... This is absolutely annoying, because I basically have to create "fake" events for every real event that gets fired in my components because the component doesn't exist..

I've tried to do creationPolicy="all" on my canvas component (used in the viewStack) but that didn't do anything useful, and I really am hating the idea of having to pollute my application with a million THISBUTTON_CLICK:String = "someuniquestringforthisspecificbutton"; values so I can do click="dispatchEvent(new Event(THISBUTTON_CLICK))"... so I can then turn arround and finally do viewComponent.addEventListener(MainScreen.THISBUTTON_CLICK, onThisButtonClick)...

There must be a better way! Help Please!

John
Pages: [1]