Hi Mike,

Observe and ObserveValue have been designed to work with MXML binding
only. The curly braces in the source and handler properties are being
treated differently by the MXML compiler than just simple ActionScript
assingments as you do in your example. Therefore, the current
implementation relies on the MXML compiler and cannot be used in
ActionScript. 

However, I'd be intersted in why you want to use data binding in an
ActionScript environment (for your ActionScript model or utility
classes). In my experience, using a pure EventDispatcher is easier to
write and most importantly to read (especially for other developer,
potentially coming from other technologies). Just let your class
dispatch a custom event when something important happens. Or if you
cannot do that easily, listen to the propertyChange event of Bindable
properties.

Best,
Alex


--- In [email protected], "Mike Anderson" <[EMAIL PROTECTED]> wrote:
>
> Hello All,
> 
> I am trying to figure out how to use the ObserveValue Component, when I
> use it inside of a Class File.
> 
> In all the examples I've seen, they all utilize the Class File as a MXML
> Component - and when I use it in this manner, it works just fine.
> 
> BUT, I really need to use this inside my Class Files - and as far as I
> can tell, I should be able to import the Class File, and create a new
> variable - casting it as an ObserveValue() - but when I use it this way,
> nothing happens.
> 
> Per the examples, here is the proper use of the file:
> 
> <ac:ObserveValue 
>       id="valueObserver" 
>       source="{ model.myVarToBeWatched }" 
>       handler="valueObserverHandler" 
>       value="true"/>
> 
> Now, I'd like to use it using pure ActionScript - and here's what I got
> so far: (keep in mind, the AS Class File below, is extending the Control
> in which it belongs to - and rest assured, that I am placing all the
> appropriate code within all the proper Event Listeners, like
> onCreationComplete, etc.)  I am just keeping it simple, for this
> particular post.
> 
> package
> {
>       import com.adobe.ac.*;
>       
>       class myClass extends Panel
>       {
>               private var myObserve:ObserveValue = new ObserveValue();
>               [Bindable]
>               public var model:ApplicationModel =
> ApplicationModel.getInstance();
>               
>               public function myClass():void
>               {
>                       initObservers();
>               }
>               
>               private function initObservers():void
>               {
>                       myObserve.source = model.myVarToBeWatched;
>                       myObserve.handler = valueObserverHandler;
>                       myObserve.value = true;
>               }
>               
>               private function valueObserverHandler( event:Event
> ):void
>               {
>                       trace( "it worked" );
>               }
>       }
> }
> 
> In my real code, I wait for the Creation Complete Event, before I
> initialize all of my Event Listeners, etc.  So you can assume that my
> real code, is properly setup.
> 
> My real question here is, when creating component written purely in AS3,
> can they be used either way - like as an inline Component in MXML, or if
> you choose, referenced within an AS3 Package?  I don't see why not,
> since MXML Controls are all just Class Files anyway...
> 
> So I just wanted to know if somebody could shed some light on what I'm
> doing wrong, or if the ObserveValue Class just wasn't designed to be
> used in this manner.
> 
> Thanks in advance for all your help,
> 
> Mike
>


Reply via email to