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" <[EMAIL PROTECTED]> 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
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
Web site design development | Computer software development | Software design and development |
Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.