all groups > flash actionscript > february 2004 >
You're in the

flash actionscript

group:

AS 2.0 class loading xml and setting status flag


AS 2.0 class loading xml and setting status flag Jan-Paul K.
2/28/2004 8:51:45 PM
flash actionscript: Hi,

I tried for hours to get a class-instance variable to be set from within a
onLoad() function that is called once an xml file is loaded in the constructor
method.

I triede several addressing methods (parent, this, root) none worked. The
value of the initialized variable is always false. The getXMLString() method is
returning the content string of the xml file, so I know the myOnLoad method has
been called and the content has been loaded successfull.

Any Ideas how I must refer to the instance variable to from within the
myOnload function?

Any hint is more than welcome!

Tanks and greetz,
Paul

class com.pironet.psa.Configurator {
var initialized:Boolean = false;
var doc:XML;
function Configurator( configFileURL:String ){
this.doc = new XML();
this.doc.ignoreWhite = true;
this.doc.load( configFileURL );

function myOnLoad() {
trace("XML loaded");
_parent.initialized = true;
// this.initialized = true;
// _root.initialized = true;
}
doc.onLoad = myOnLoad;
}

function getXMLString(){
return this.doc.toString();
}
}
Re: AS 2.0 class loading xml and setting status flag Christoffer Enedahl
3/1/2004 9:46:07 AM
try:
doc.onLoad = function (success){
trace("XML loaded");
search.path.to.your.object.initialized = true; //<--- this is important.
// this.initialized = true;
// _root.initialized = true;
}

HTH/Christoffer

"Jan-Paul K." <webforumsuser@macromedia.com> skrev i meddelandet
news:c1qv11$9gg$1@forums.macromedia.com...
[quoted text, click to view]

Re: AS 2.0 class loading xml and setting status flag Carl Ballantyne
3/26/2004 4:22:58 PM
I am having exactly the same problem and have been hitting a brick wall for
about 2 weeks now.
I can see the only way seems to be to use the full path to the instance
variable you are trying to change. But how can you find this dynamically?

The only way I have been able to change it is by using something hardcoded
like _level0.instanceName.initialized = true;
How do you find the value for the path to the object from within the onLoad
function. In the previous post by Christoffer is this was the 3rd line:
search.path.to.your.object.initialized = true; //<--- this is important.

BTW - I noticed that if you call myOnLoad with like the following:
doc.onLoad = myOnLoad;
then you can access and set the variable initialized without using the full
path to the object. But then the XML object doc does not seem to be properly
set. And also you do not have access to the success variable which is very
important.
Re: AS 2.0 class loading xml and setting status flag Carl Ballantyne
4/3/2004 4:37:38 PM
Come on guys,
Someone out there must have built a component or ActionScript 2.0 class that
can load an XML file. Or even and loadVars?

There is a possible workaround where you can override the onEnterFrame
function for the instance created and check the status of the xml object. But
this will not catch situations where the path to the file is incorrect. You
must be able to override the onLoad function for the xml object to correctly
load the XML.

Ideas , Suggestions, Wild Guesses are weclome.
Re: AS 2.0 class loading xml and setting status flag Jan-Paul K.
4/3/2004 6:13:50 PM
I solved my problem by making my AS 2.0 Class extending the original XML class.
I don't work with intance variables anymore but using the onload method of the
extended XML class in order to send an event once the xml is loaded completely.
maybe it helps somebody.

Paul



import mx.events.EventDispatcher;

XMLConfigurator extends XML {

var debug:Boolean = true;
private var ignoreWhite:Boolean = true;

function dispatchEvent() {};
function addEventListener() {};
function removeEventListener() {};

function XMLConfigurator() {
super();
// set instances up as dispatchers:
mx.events.EventDispatcher.initialize(this);

this.onLoad = function(){
super();
trace("[XMLConfigurator] initialized successfull / debugging is set to " +
this.debug );
var eventObj:Object={target:this,type:"onInitialized"}
eventObj.msgtxt = "[XMLConfigurator initialized]";
// dispatch the event
dispatchEvent(eventObj);
}
}

function getXMLString(){
return this.toString();
}
}
Re: AS 2.0 class loading xml and setting status flag Carl Ballantyne
4/20/2004 4:55:42 PM
Jan-Paul K,
Thanks for the tip! I did something similar with my Component class. Instead
of creating an XML object I created a separate class which extended the XML
class and dispatched events to the component class when certain things occurred
like a successful parsing of the xml or a file not found or an unsuccessful
parse of the xml.

AddThis Social Bookmark Button