Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-14-2008, 06:01 AM   #1
ellils
Registered User
 
Join Date: Sep 2007
Posts: 1
Default Variable Scope Question...

Hi guys,

I have a variable scope problem with this code:
Code:
var XML4:XML = new XML();  
var pathtologo = new String();
XML4.ignoreWhite = true;
XML4.onLoad = function(success) {
	if(success){
		pathtologo = XML4.firstChild.childNodes[3];
	        trace("(1) Path to logo is: "+pathtologo);
       }
}
conXML4.load("common.xml");

trace("(2) Path to logo is: "+pathtologo);
trace on (2) gives no value and I would like to somehow get the value there instead of being forced to use only method (1) to generate a value.

How should I do that?
ellils is offline   Reply With Quote
Old 05-14-2008, 07:22 AM   #2
Noct
Toys in the Attic...
 
Noct's Avatar
 
Join Date: Oct 2006
Location: NY
Posts: 3,022
Default

Welcome aboard,

Scope isn't the issue here. The problem is that your second trace actually fires before the xml is loaded, at which point your variable still has no value.

You need to wait until the xml is fully loaded. For example, this would probably do the trick:
ActionScript Code:
var XML4:XML = new XML(); var pathtologo:String; XML4.ignoreWhite = true; XML4.onLoad = function(success) {     if (success) {         pathtologo = this.firstChild.childNodes[3];         trace("(1) Path to logo is: "+pathtologo);     } }; XML4.load("common.xml"); this.onEnterFrame = function() {     if (pathtologo) {         trace("(2) Path to logo is: "+pathtologo);         delete this.onEnterFrame;     } };
__________________
http://rwithers.com
Noct is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variable thebutterfly ActionScript 2.0 72 01-24-2006 03:12 PM
Skinning components with embedded components epeace Components 5 06-16-2005 08:35 PM
Variable scope question tryin_to_learn ActionScript 2.0 5 05-22-2005 02:37 PM
Creating dynamic textfields with variable names question Johan35 ActionScript 1.0 (and below) 4 06-18-2003 03:42 PM
simple variable question jkd77 ActionScript 1.0 (and below) 2 12-11-2001 06:22 PM


All times are GMT. The time now is 09:28 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.