Getting all the popups in a Flex application

Flex Published on December 19, 2009 by Andrea Bresolin No Comments »
Live demoSource code (LICENSE)

In Flex, you can create popups easily, but what if you want to get all of them after they’ve already been created? You could keep track of every created popup using a customized function that puts every single instance in an array for example, but what if you’re using a Flex component that simply creates popups in its own way and you cannot keep track of what it creates? Here I’m going to provide a possible solution.

After some debugging, I found out that Flex puts all the popups among the rawChildren in the application’s SystemManager. This is where we can find them. So now that we know where to look, we need a way to distinguish the children that are popups from those that are not (rawChildren does not contain only popups). If we use only components whose base class is the standard UIComponent class (I think this is the case most of the times), there’s an easy way to know if an instance is a popup or not: the isPopUp property of UIComponent.

Whenever we create a new popup that extends UIComponent, the PopUpManager sets the isPopUp property to true. So, all we need to do is cycle through the application’s systemManager.rawChildren and check whether we find an UIComponent instance whose isPopUp property is true. In that case, we’ve got an application’s popup.

To demonstrate the concept, I’ve implemented the PopUpUtils class. It simply allows you to get all the popups inside an application instance, to discover if there are visible popups and to close all the popups. Let’s take a look at it. Read the rest of this entry »

Dynamic ObjectProxy

Flex Published on December 6, 2009 by Andrea Bresolin 2 Comments »
Live demoSource code (LICENSE)

The problem: I’ve got a Flex class with all its properties well defined. It’s good for me, it has all the properties I need to represent correctly the model, but sometimes I wish I had a few more properties to use it in some contexts. These additional properties are not strictly related to the model I want to represent, so I don’t want to add them to the class, but I need them to easily integrate with Flex components functionalities for user interaction.

The solution: DynaObjectProxy!

Before looking through the source code of DynaObjectProxy, let’s talk briefly about what it does. Basically, it’s a sort of ObjectProxy, but it extends its functionalities.

With ObjectProxy you can wrap a class instance and access to its properties through the proxy

// MyClass contains the property "prop1"
var myClassInstance: MyClass = new MyClass();
myClassInstance.prop1 = "The value";

var myProxy: ObjectProxy = new ObjectProxy(myClassInstance);

trace(myProxy.prop1); // Outputs "The value"

but you cannot dynamically create new properties in the ObjectProxy instance

trace(myProxy.prop2); // ERROR! "prop2" doesn't exist in MyClass

Otherwise, you can create an ObjectProxy instance without wrapping a class instance and in this case you actually can create new properties in the ObjectProxy

var myProxy: ObjectProxy = new ObjectProxy();
myProxy.prop2 = "The property value";

trace(myProxy.prop2); // Outputs "The property value"

What if I would like to have both the functionalities? DynaObjectProxy allows exactly this: you can both wrap a class instance and create new properties keeping all the new properties bindable at the same time.

Now we can start looking through the DynaObjectProxy source code and later we’ll see how it can be used with an example. Read the rest of this entry »

WP Theme & Icons by N.Design Studio
©2009-2010 Andrea Bresolin. All rights reserved. - Privacy Policy
Entries RSS Comments RSS