PDA

View Full Version : can you do referencing/pointers in flex/as?


magquatre
08-03-2007, 01:37 AM
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="blahblah" creationComplete="before_click()">

<mx:Script>
<![CDATA[

[Bindable]
public var my_string:String = new String();


public function before_click():void
{
my_string = "This is before the button was clicked"
my_panel.title = my_string;
}


public function after_click():void
{
my_string = "This is after the button was clicked"
my_button.label = "i just got clicked!";
}

]]>
</mx:Script>

<mx:Panel width="557" height="501" title="" id="my_panel">
<mx:Button label="Button" id="my_button" click="after_click()"/>
</mx:Panel>

</mx:Application>


The purpose of this code is to assign a string variable to my_panel.title
So when i click on the button, it updates the my_string variable, which should then (somehow) update the my_panel.title variable. Of course, this is not what happens. Is there anyway i could store a reference of my_string into my_panel.title so that the correct behavior occurs? I know that an easy solution is to do this:


<mx:Panel width="557" height="501" title="{my_string}" id="my_panel">


But that is not what i want. Because i may want to create my panel object dynamically through actionscript. Is it possible to do some sort of referencing/pointer voodoo in actionscript to get this to work? Or will i have to resort to manually updating each flex component's properties that i want to have changed?

Thanks

drkstr
08-03-2007, 01:45 AM
I could be wrong, but I have not seen a way to use pointers in AS3. It seems to just do by default for all non-standard data types.

FYI, you can use binding in AS classes as well, which will achieve the same purpose. It's a pretty nifty feature when you dig into it. If you search for "Binding" in the Flex Builder help, you will have a treasure trove of information.

If I am wrong about the pointers, hopefully someone will speak up cause I would like to know too.

Best regards,
...aaron

magquatre
08-03-2007, 05:42 AM
Ah, thanks!

BindingUtils does exactly what i want!

BindingUtils.bindProperty(main_panel, "title", my_button, "label");


This will bind the value of my_button.label to main_panel.title , so whenever my_button.label changes, main_panel.title changes as well.

Thanks for the direction!

senocular
08-03-2007, 01:02 PM
Its true that AS does not support pointers.