all groups > flash data integration > june 2006 >
You're in the

flash data integration

group:

XML onLoad problem


XML onLoad problem LostFlashSoul
6/28/2006 5:10:19 PM
flash data integration:
I'm calling an external xml file and loading it into Flash.

I can only pull the varables out in the onLoad function. Here it is.

var courseXML:XML = new XML();
courseXML.ignoreWhite = true;
courseXML.load("presentSlidesOne.xml");


courseXML.onLoad = function(bSuccess:Boolean):Void {
if (bSuccess && this.status == 0) {
var xnRoot:XMLNode = new XMLNode(3, this.firstChild);
var xnHelpText:XMLNode = new XMLNode(3,
this.firstChild.firstChild);
trace(xnHelpText.nodeValue);
}
else {
trace("document failed to load or parse.");
}

};


//stop();

All these trace statements produce the desired result.

However, I can't get the data out and available globally. In other words, I
want the same variable statements to exist outside the onLoad function call, so
that I can actually use the data. Anybody know how to do this?

Thanks,
Re: XML onLoad problem Motion Maker
6/28/2006 9:23:20 PM
Declare variable outside the onLoad method. Ex:
var xnRoot:XMLNode;
var xnHelpText:XMLNode;
then use them inside onLoad. ex:
xnRoot= new XMLNode(3, this.firstChild);
xnHelpText = new XMLNode(3, this.firstChild.firstChild);

As well you can use the courseXML variable outside the onLoad
var xnRoot:XMLNode = new XMLNode(3, courseXML.firstChild);
In this case you call another function to use it or move to another frame.



--
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
[quoted text, click to view]

Re: XML onLoad problem Motion Maker
7/16/2006 9:36:48 PM
Do not see str in the code? Perhaps you mean testFromFile?


_root.dbox.text = ":: " + textFromFile ;
You would want the above line to be inside the onLoad method or in a
function called by the onLoad method.

Also realize with anonomous function assignments the do occur at run time
and not a compile time. Thus you do want to have the onLoad assignment
before the load method. Because the load method is dependent on network
traffic, often the timing allows the order you have, but often in testing
the speed is such load completes before the onLoad line is reached and thus
load did not know about the callback function. Overall you do not want code
where there is an outside chance that the load method would complete before
the assignment line for onLoad. In summary you want to execute function
assignments before they could be used.

--
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
[quoted text, click to view]

Re: XML onLoad problem thephatp
7/16/2006 10:05:04 PM
Hi Lon,

I'm having a similar problem, and I've already declared the variables outside
of the scope. I'm not sure how scoping works in Flash (but I do in general, as
I'm a software developer), but this doesn't seem to be doing what is expected.
Here is a very shortened version of what I'm tring to do:

var myLoadableData = new LoadVars() ;
myLoadableData.load( myFile ) ;

var textFromFile:String ;

myLoadableData.onLoad = function( success )
{
if( success )
{
textFromFile = myLoadableData.songVar ;
}
}

_root.dbox.text = ":: " + textFromFile ;


At this point, str is null / undefined. Any ideas?

[q][i]Originally posted by: [b][b]Newsgroup User[/b][/b][/i]
Declare variable outside the onLoad method. Ex:
var xnRoot:XMLNode;
var xnHelpText:XMLNode;
then use them inside onLoad. ex:
xnRoot= new XMLNode(3, this.firstChild);
xnHelpText = new XMLNode(3, this.firstChild.firstChild);

As well you can use the courseXML variable outside the onLoad
var xnRoot:XMLNode = new XMLNode(3, courseXML.firstChild);
In this case you call another function to use it or move to another frame.

[/q]



var myLoadableData = new LoadVars() ;
myLoadableData.load( myFile ) ;

var textFromFile:String ;

myLoadableData.onLoad = function( success )
{
if( success )
{
textFromFile = myLoadableData.songVar ;
}
}
Re: XML onLoad problem Motion Maker
7/17/2006 8:31:47 PM
The steps:

1. Either load or sendAndLoad methods are called. Applies to LoadVars and
XML classes.

2. Then the code following the load or sendAndLoad is executed immediately
as fast as the processors can.

3. At some point after load or sendAndLoad, but not necessarily immediately
after, the onLoad method is called.

The onLoad event method is a callback. It sits idle and when the load or
sendAndLoad methods have done their work, they call the onLoad method.

So all the lines following the onLoad function assignment, load or
sendAndLoad are likely to be processed before the loading is done.

So any coding dependent on the data having been received, must be in the
onLoad method or a function called by it.


--
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
[quoted text, click to view]

Re: XML onLoad problem thephatp
7/17/2006 9:11:06 PM
Hi Lon,

thanks for the info. I was wondering if that would matter. I've gotten so
close now, to getting this working, but I can't seem to make it work
completely. I'm doing all of this in a class, so it's making it a little
different. I read somehwere that the onLoad function doesn't process until the
end of the frame (after the frame completes), so I'm getting the values at the
wrong time. Is there a way to force the onLoad immediately?

Maybe putting the code BEFORE the load function will help. I'll try that, but
I think I tried that last night and it didn't work. But i'll try it again.

Thanks!

Chad

[q][i]Originally posted by: [b][b]Newsgroup User[/b][/b][/i]
Do not see str in the code? Perhaps you mean testFromFile?


_root.dbox.text = ":: " + textFromFile ;
You would want the above line to be inside the onLoad method or in a
function called by the onLoad method.

Also realize with anonomous function assignments the do occur at run time
and not a compile time. Thus you do want to have the onLoad assignment
before the load method. Because the load method is dependent on network
traffic, often the timing allows the order you have, but often in testing
the speed is such load completes before the onLoad line is reached and thus
load did not know about the callback function. Overall you do not want code
where there is an outside chance that the load method would complete before
the assignment line for onLoad. In summary you want to execute function
assignments before they could be used.[/q]
AddThis Social Bookmark Button