Thanks Alex!

With the help of Dimitrios, I was able to accomplish what I needed to.

Still, using your cool little utility Class, it makes it really easy for
somebody to listen for very particular changes in a variable.

Since I am using Cairngorm, and the nature of Cairngorm centralizes
everything in the Model, I was trying to Dispatch Custom Events, from my
Commands (and failing miserably).

Using the method I just learned (getters, setters, and events), this way
is much cleaner.

Again, thanks for your reply -

Mike 

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Uhlmann
Sent: Tuesday, January 16, 2007 11:52 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: ObserveValue, and how to reference within AS3
Class File

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 flexcoders@yahoogroups.com, "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
>




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links



Reply via email to