Thanks a lot
X.
On 10/27/06, Xavi Beumala <[EMAIL PROTECTED]> wrote:
Hi all,
I'm experiencing some weird behaviours when using Bindings.
AFAIK, when we use [Bindable] a strong reference is created when the addEventListener is performed.
The problem is that I have an screen ( myScreen.mxml) which is loaded through PopUpManager inside a TitleWindow. On the other hand, myScreen.xml has some bindings defined. When I close the popUp, myScreen should bet garbage collected, but this is no possible due to the strong references in the EventDispatcher created by the Bindings. This is causing some problems, becaus if I relaunch again the MyScreen.mxml all bindings are triggered twice (because there are two listeners, one for each previously created instances of MyScreen), and so on. So if I've opened 10 times the same window, all bindings are triggered 10 times (causing for example 10 requests to the server).
Here's some demo code:
[MAIN APPLICATION]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx=" http://www.adobe.com/2006/mxml "
layout="vertical" >
<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
private var i:int = 0;
private var window:TitleWindow;
private function launchPopUp():void
{
ModelLocator.getInstance().testVar = i++;
window = PopUpManager.createPopUp(this,TitleWindow,true) as TitleWindow;
window.title = "hola";
window.showCloseButton = true;
var clazz:Class = MyScreen;
var child:DisplayObject = new clazz();
window.addEventListener (CloseEvent.CLOSE, onClose);
window.addChild(child);
}
protected function onClose (event:CloseEvent):void
{
window.removeAllChildren();
PopUpManager.removePopUp (window);
window = null;
}
]]>
</mx:Script>
<mx:Button label="Hola" click="launchPopUp()"/>
</mx:Application>
[------> MySCREEN.mxml <--------]
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml " width="400" height="300">
<mx:Script>
<![CDATA[
protected function set dest (d:String):void
{
trace ("modified");
}
]]>
</mx:Script>
<mx:Binding source="ModelLocator.getInstance().testVar" destination="dest"/>
<mx:Text text="hola mundo"/>
</mx:Canvas>
[------> ModelLocator.as <--------]
package {
[Bindable]
public class ModelLocator {
private static var instance:ModelLocator;
public function ModelLocator() {
instance = this;
}
public static function getInstance():ModelLocator {
if (instance == null) {
instance = new ModelLocator();
}
return instance;
}
public var testVar:int;
}
}
What you will see when running this code is that everytime you launch a popUp the number of printed traces increments by one.
The problem is that the application is fully based on Bindings and would be a hard work to stop using them. Is there any way we can do to force Bindings to use weakReferences?
Help much apreciated!
X.
__._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
| Software development tool | Software development | Software development services |
| Home design software | Software development company |
Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
__,_._,___

