Tuesday, July 29, 2008

Fat Models

no not those models :P CakePHP models :)

If you find your self doing something like this in the controller:

$this->A_Model->query("update somedatabase set idstatus = '".$idstatus."', statuslastmodified = '".time()."' where idproject = '".$idproject."' and UID= '".$UID."'");


consider putting this type of logic as a function in the model and then calling the function.

Better yet try not to use custom queries if you can and use the model's built in functions.

Tuesday, July 22, 2008

Flex MXML binding The entity name must immediately follow the '&' in the entity reference

So your trying to do some mxml binding with conditional logic like:


<mx:Button label="Sign In" enabled="{emailTextInput.text != '' && passwordTextInput.text != '' }" />


when you compile you get this error, "The entity name must immediately follow the '&' in the entity reference"

THe parser looks at the & and expects an entity reference because the &
signifies the start of an entity reference within XML. So how do we tell it that it's actually a condition-AND operator?

Replace each of the & '& a m p ;' <-- no spaces


Compile, and viola it works!

Wednesday, July 16, 2008

Flex: Is it a memory leak?

tutorial how flash garbage collection works:

http://blogs.adobe.com/aharui/GarbageCollection/GCAtomic.ppt



heres a couple good quotes from the presentation:

-The collector is not guaranteed to find all collectible blocks in one pass
Don’t want to interfere with rendering and interaction, Thus memory may never return to the initial point

-You are generally only concerned about repeatable sequences: Popup dialogs coming and going Modules loading and unloading. If you repeat these sequences often over a long period of time, the amount of totalMemory will hit some maximum value and stay at or below it if you are not leaking memory.

-Garbage Collection is not predictable



good tutorial on using the flex profiler:

http://www.peachpit.com/articles/article.aspx?p=1182473&seqNum=2




Tuesday, July 15, 2008

Flex Actionscript 3.0 Missing DisplayObject Children

So you have a component like


Awesome.mxml

<mx:Canvas ....>
<mx:Vbox id="avbox" />
</mx:Canvas>



if you try to create your object with as3 like:



var awesome:Awesome = new Awesome();



you'll see that



trace(awesome.avbox); //NULL



gives you null. Thats because your component's children are created using deferred instantiation. If you want to force the component to create its children do:


awesome.initialize();


now when you try:


trace(awesome.avbox); //NOT NULL


there will actually be something there :)

Actionscript 3.0 Flex Modules Tricky Timer Memory Leak

Becareful when unloading modules to stop and remove Timers, these can cause you memory leaks (and headaches)!!

Friday, July 11, 2008

PureMVC Pipes disconnecting the pipes after a module is unloaded TeeSplit

because TeeSplit can't remove a pipefitting of our choosing I extended it
and added in this method:


public function removePipeFitting(inpipe:IPipeFitting):IPipeFitting {
var outputsac:ArrayCollection = new ArrayCollection(outputs);

if (outputsac.getItemIndex(inpipe) >= 0) {
return outputsac.removeItemAt(outputsac.getItemIndex(inpipe)) as IPipeFitting;
}
return null;

}




in a PipeAwareModule you can add a reference to the pipes connecting to it.



private var _cachedPipes:ArrayCollection = new ArrayCollection([]);


/**
* used to remove pipes at the shell's side of the junction
*
* @param pipefitting we are going to call disconnect on this pipefitting
* @param output
*
*/
public function cacheFitting(pipefitting:IPipeFitting, output:IPipeFitting):void {
_cachedPipes.addItem({pipefitting:pipefitting, output:output});
}

/**
* goes through the arraycollection disconnecting the pipefitting from output
*
*/
public function removepipes():void {
for each (var pipefittings:Object in _cachedPipes) {
if (pipefittings.pipefitting is TeeSplitImproved) {
(pipefittings.pipefitting as TeeSplitImproved).removePipeFitting(pipefittings.output);
}
else {
(pipefittings.pipefitting as IPipeFitting).disconnect();
}
}
_cachedPipes.removeAll();
}


if your module has a unload method you'd want to:

1] call facade.removeMediator on every mediator (in the junction mediator's onRemove method do junction.removePipe on all pipefittings attached to that junction), facade.removeProxy, ..etc
2] call the removepipes() to remove incoming pipes, then
3] call facade.removeCore to get rid of all the core actors.

PureMVC Pipes Connecting / Disconnecting Pipes TeeMerge


===pipe1========= teemerge ---------------
|
======pipe2==========|


To get something like above you could either do


pipe1.connect(teemerge);
pipe2.connect(teemerge);


OR equivalently


teemerge.connectInput(pipe1);
teemerge.connectInput(pipe2);




disconnecting pipes

lets say we had:

======pipe1========pipe2==========pipe3=========

doing:
pipe1.disconnect().disconnect().disconnect();


would result in:


=====pipe1 pipe pipe3

because each disconnect returns the disconnected pipe






===teesplit==============pipe1=====
|
|==========pipe2=====
|
|==========pipe3=====


in this case

teesplit.disconnect();
teesplit.disconnect();
teesplit.disconnect();

removes all 3 pipes in the reverse order that you connected them.


there is no built in capability to remove a pipe of your choosing at the moment(something you need if your gonna be doing a lot of module building!!).

check here to see how someone implemented it themself:
http://forums.puremvc.org/index.php?action=printpage;topic=508.0