[flexcoders] How does [Bindable] work? - For integration of Flash CS3 content in a Flex 2 app

2007-04-24 Thread João
Hello, 

we are giving the first steps on defining a workflow with designers
for integrating Flash CS3 content on our Flex 2 applications, using
the Flex Component Kit for Flash CS3 on labs
(http://labs.adobe.com/wiki/index.php/Flex_Component_Kit_for_Flash_CS3).

I have made a test case where we simply have on Flash CS3 one
movieclip draggable that updates a public variable on the exported
class with it's current x position, when dragged.
Then, I have successfully imported the generated SWC to Flex 2, as you
can see on
http://www.riapt.org/opensource/FlashIntegration_Bindable/FlashIntegration_Bindable.html
(view source enabled, and the zip file has the Flash CS3 source code).

What i want to achieve can be easily understand with the code:

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
layout=absolute xmlns:local=* backgroundColor=0xFF
viewSourceURL=srcview/index.html
mx:Text x=10 y=10 text={flashscroller.posx}/
local:FlashScroller id=flashscroller x=10 y=100/
/mx:Application

I want to bind the text on my TextBox to the posx public var on
FlashScroller.as (see the fla.zip inside the source). The first time i
tried this, obviously Flex complained that flashscroller.posx wasn't
bindable. Ok, so i tried in Flash CS3 to add the [Bindable] metadata
to the posx variable. And it didn't complain. But it also didn't work:
now neither Flash CS3 or Flex 2 compilers give errors, but the code
don't work, since the textbox isn't properly update.

I guess i can't use [Bindable] on Flash CS3 content, but it would be
important to recreate the feature to allow better integration between
flash and flex. Is there a solution to this? Maybe recreate in AS3
what the [Bindable] does behind curtains?

Thanks, 

João Saleiro





Re: [flexcoders] How does [Bindable] work? - For integration of Flash CS3 content in a Flex 2 app

2007-04-24 Thread João Fernandes
João,

you can set your property [Bindable('posxChanged')] and when your code 
updates that value, you just dispatch a posxChanged event, and the 
getter will be called again.

something like this

[Bindable('posxChanged')]
public function set posx(val:Number):void{
if(_posx == val) return;
_posx = val;
dispatchEvent( new Event('posxChanged') );
}
public function get posx():Number{
return _posx;
}

it should work for you.

João Fernandes