OK, yeah, thanks. I was also facing the problem when I was
instantiating classes and setting properties w/o URLLoader. I created
a very simple example and I realized the problem was my misuse of
[Bindable]. I'm using Cairngorm and have all my VO objects in the
ModelLocator...well, my many VO objects don't have [Bindable] declared
within those classes. I lazily assumed that having [Bindable] declared
in the ModelLocator would take care of everything for me. Not the
case...once I added [Bindable] to each VO, everything appeared in the
UI correctly. Which makes sense b/c my trace statements had the value
but the UI was not updating. Sorry for the newbie brain fart!!  
Thanksa again Pete.

--- In flexcoders@yahoogroups.com, "Peter Farland" <[EMAIL PROTECTED]> wrote:
>
> Ah, right, much clearer now that I see this code.
> 
> 
> The issue is that a request to an HTTP URL via something like URLLoader
> is asynchronous, so the SWF script is not held up waiting for the
> network to respond. This means you will need to wait until the response
> comes back some time later, i.e. when the result handler is called,
> before accessing the generateXML property.
> 
> So, I would architect this a little differently.
> 
> Decouple the logic for loading XML into a service helper class and then
> when you get back a response pass that to a utility method to actually
> generate the XML.
> 
> 
> -----Original Message-----
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of Suzy Lawson
> Sent: Monday, June 05, 2006 11:52 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Re: Instantiation and setting problems - Example
> included
> 
>   Thanks for your response...this error is still haunting so I included
> a simple example to show my problem of class variables not being able to
> be set after I initialize a new class. Even if I move the "generateXML"
> method into the complete Handler....the same null pointer is still
> thrown. Any ideas why??
> 
> Top-level MXML file:
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute">
>       <mx:Script>
>               <![CDATA[
>               private function setValue() : void
>               {
>                       var testA : TestA = new TestA();
>                       xmlValue.text =
> testA.generateXML("55").toXMLString();
>               }
>               ]]>
>       </mx:Script>
>       <mx:Button label="Set Value" click="setValue()"/>
>       <mx:Label id="xmlValue"/>
> </mx:Application>
> 
> _-----------------------------------------
> //TestA class
> package
> {
>       import flash.events.Event;
>       import flash.net.URLLoader;
>       import flash.net.URLRequest;
> 
>       
>       public class TestA
>       {
>               private var sampleXML : XML ;
>               
>               public function TestA() : void
>               {
>                       var loader : URLLoader = new URLLoader();
>             loader.addEventListener(Event.COMPLETE, completeHandler);
>                       loader.load(new URLRequest("sample.xml"));
>               }
>               
>               private function completeHandler(event:Event):void {
>             sampleXML = new XML(event.target.data);
>       }
>       
>       public function generateXML(value : String) : XML
>               {
>                       [EMAIL PROTECTED] = value; // error is here b/c
> sampleXML is 'null'
>                       return sampleXML;
>               }
>       }
> }
> ------------------------------------
> sample.xml file:
> <test id="" data=""/>
> --------------------------
> The exact error I get is:
> TypeError: Error #1009: Cannot access a property or method of a null
> object reference.
>       at TestA/generateXML()[C:\flex\TestA.as:25]
>       at sampleBug/sampleBug::setValue()[C:\flex\sampleBug.mxml:8]
>       at sampleBug/___Button1_click()[C:\flex\sampleBug.mxml:12] 
> 
> --- In flexcoders@yahoogroups.com, "Peter Farland" <pfarland@> wrote:
> >
> > I'd have to see the code to really understand what is going on, but
> can you avoid doing anything in a constructor and use a button or
> something to trigger the work to see if that's the issue?
> > 
> > -----Original Message-----
> > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED]
> On Behalf Of Suzy Lawson
> > Sent: Friday, June 02, 2006 4:54 PM
> > To: flexcoders@yahoogroups.com
> > Subject: [flexcoders] Re: Instantiation and setting problems
> > 
> > I'm using the Cairngorm framework, so in the implented Command
> classes...
> > 
> > For the XML problem, it's in a class that the Command class calls.
> The constructor load the XML file stored locally, then the
> completeHandler  calls XML(event.target.data) and assigns the XML to a
> local variable.
> > 
> > However, when I instantiate this object, then call a method on it,
> the XML is still null. If I put a timer on it to stall for a second,
> it's there....
> > 
> > --- In flexcoders@yahoogroups.com, "Peter Farland" <pfarland@> wrote:
> > >
> > > 
> > > Where are you declaring these classes?
> > >  
> > > 
> > > -----Original Message-----
> > > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED]
> > On Behalf Of Suzy Lawson
> > > Sent: Friday, June 02, 2006 12:01 PM
> > > To: flexcoders@yahoogroups.com
> > > Subject: [flexcoders] Instantiation and setting problems
> > > 
> > > I anyone else having issues trying to set values on objects for
> > newly instantiated objects in an object graph with 3 or more layers? 
> > > 
> > > I have the following:
> > > 
> > > ClassA {
> > >  public var classB : ClassB;
> > >  public var classC : ClassC;
> > > }
> > > 
> > > ClassB {
> > >  public var classD : ClassD;
> > > }
> > > 
> > > ClassC {
> > >  public var textVal : String='';
> > > }
> > > 
> > > and i have a value sets in the ModelLocator (cairngorm) class like
> so:
> > > public var allClassAs : ArrayCollection; public var selectedClassA :
> > ClassA;
> > > 
> > > The problem is if I retrieve a single 'ClassA' from the collection
> > of allClassAs using the ID of the selectedClassA, then try to make a
> call like this:
> > > classA.classC.text="Whatever";
> > > 
> > > The mxml field I have bound to that value never displays and I get
> > the following debug error.
> > > 
> > > error during evaluation
> > > no such variable: classA.classC.textVal
> > > 
> > > This kind of makes sense since classC wasn't initialized yet, so
> > even if I change ClassA to be:
> > > ClassA {
> > >  public var classB : ClassB = new ClassB();  public var classC :
> > ClassC = new ClassC(); }
> > > 
> > > I still get the same error. In the UI, if I click back, it appears
> > correctly, but the first time it always fails. It seems like the set
> > > (classA.classC.text="Whatever";) is getting called faster then the
> > object can be initialized (constructed). 
> > > 
> > > I've had similar problems when calling:
> > > var myXML = new XML(event.target.data); [EMAIL PROTECTED]"3232";
> > > 
> > > When I debug this, myXML is still null when the 2nd line is called.
> > A work around is to instantiate the XML on startup so the XML is
> there before calling the set on @ID, but means more memory. 
> > > 
> > > Anyone else hitting these issues?  
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > ------------------------ Yahoo! Groups Sponsor
> > --------------------~--> Everything you need is one click away. 
> Make Yahoo! your home page now.
> > > http://us.click.yahoo.com/AHchtC/4FxNAA/yQLSAA/nhFolB/TM
> > > --------------------------------------------------------------------
> > > ~-
> > > >
> > > 
> > > --
> > > 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
> > >
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > ------------------------ Yahoo! Groups Sponsor
> --------------------~--> Home is just a click away.  Make Yahoo! your
> home page now.
> > http://us.click.yahoo.com/DHchtC/3FxNAA/yQLSAA/nhFolB/TM
> > --------------------------------------------------------------------~-
> > >
> > 
> > --
> > 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
> >
> 
> 
> 
> 
> 
> ------------------------ Yahoo! Groups Sponsor --------------------~-->
> Get to your groups with one click. Know instantly when new email arrives
> http://us.click.yahoo.com/.7bhrC/MGxNAA/yQLSAA/nhFolB/TM
> --------------------------------------------------------------------~-> 
> 
> --
> 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
>







------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get to your groups with one click. Know instantly when new email arrives
http://us.click.yahoo.com/.7bhrC/MGxNAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
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

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to