PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: danmvc on July 13, 2009, 12:57:25



Title: Call a Command Every Frame
Post by: danmvc on July 13, 2009, 12:57:25
Is it ok to call a command every frame? I'm just wondering since the command object is created every time it is called, won't this be a memory problem?


Title: Re: Call a Command Every Frame
Post by: puremvc on July 13, 2009, 01:40:41
Depends on what you want to do. If it's calling a proxy method, you might want a long-lived mediator to handle this.

-=Cliff>


Title: Re: Call a Command Every Frame
Post by: danmvc on July 14, 2009, 01:20:32
Well I was just messing around with having a box that the user could scale. The proxy holds the data of the width and height of the box. On mouse move, the mouse position is sent to the command, the command figures out what the new size of the box should be, updates the proxy, and tells the mediator how to visually represent the new box size.

The mediator I'm using is 'long-lived,' in that it is my main module mediator. I'm just not sure what's going on under the hood when I send a notification every frame that is mapped to a command. Is the command actually created on every call?


Title: Re: Call a Command Every Frame
Post by: Tekool on July 14, 2009, 02:38:00
Here I think that all this work would better have to be done by only one mediator. You don't need a proxy to store the mouse position data, it's only a view concern, except if your mouse position is sent on a network for a multiplayer game or something else. And even in this case, you'll have the mouse position first "stored" by a mediator.

Try not to use the main mediator for this, create a BoxMediator or something specific. And then you're mediator can subscribe to the ENTER_FRAME event of the box Sprite/MovieClip. I don't think that you need a command for that, but as Cliff previously said, it all depends on your needs.


Title: Re: Call a Command Every Frame
Post by: danmvc on July 15, 2009, 12:39:55
I was thinking just a mediator would be fine, but I was trying to use the MVC framework pretty much just to learn the thing. But my concern then was that there would be logic inside the mediator, I didn't think this was proper. For instance, assume that the box has properties like minimum width or a maximum boundary. During the resize, I would need to perform logic that constrains the resizing to these areas. I would think that that type of logic  would traditionally be inside a controller object.

I guess it would be fine if the mediator can communicate directly with the proxy, to reference it's minimum maximum properties, is this proper?


Title: Re: Call a Command Every Frame
Post by: puremvc on July 15, 2009, 01:57:52
Have a look at the HelloFlash demo. I think you'll find some useful ideas there.

http://trac.puremvc.org/Demo_AS3_Flash_HelloFlash

-=Cliff>