335 posts
  • Weekly Top Seller
  • 7 Years of Membership
  • Featured Item
  • Author Level 5
+9 more
tiam
says

Hello! Im rubbing my head with a little problem and couldnt think of a better place to ask for help :)

Im making a file where I want to import some settings into actionscript from a xml fil but I cant find out how to get the xml content out of the xml declaration…

here is the code

settingXML = new XML ; settingXML.ignoreWhite = true; settingXML.onLoad = function(loaded) { if (loaded) { }

var dub = this.firstChild;
var setting = dub.attributes;
var start_var = setting.start;
var about_var = setting.about;
var portfolio_var = setting.portfolio;        
var contact_var = setting.contact;

trace(start_var) settingXML.load(“settings.xml”);

}

I want to be able to get the variables imported with xml to work outside of the xml declaration so that I could use these variables elswhere maybe in another mc.

How do I do this? Thanks for any help :)

4335 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 3
  • Beta Tester
+11 more
Reaper-Media
says

You should already be able to refer to them / use them from outside that decleration.

ie:
my_mc.variable
where my_mc is the movieclip which loads the XML (can be _root or _parent)
and variable is the variable which you want to use (e.g. contact_var)
335 posts
  • Weekly Top Seller
  • 7 Years of Membership
  • Featured Item
  • Author Level 5
+9 more
tiam
says

Thanks a lot for the answer Reaper-Media!!

However it seems like when trying to access the var outside the declaration the xml is not loaded… I tried to trace outside but just gets undefined. and when tracing the xml loaded outside i get that it is not loaded. is there any way to make the variable only load if the xml is loaded ? :)

675 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • Weekly Top Seller
+7 more
dexterous
says

Are you declaring your variables inside the onLoad function using the ‘var’ key word. This makes the variables as ‘local’ for the function and they will be removed after the function block.

To use the variable outside the function block, declare them outside. And then you can use them anywhere as Reaper has said.

var setting:String; var start_var:String; var about_var:String;

settingXML = new XML ; settingXML.ignoreWhite = true; settingXML.onLoad = function(loaded) { if (loaded) { var dub = this.firstChild; start_var = dub.attributes; about_var = setting.start; } trace(start_var);

}

settingXML.load(“settings.xml”);

HTH

335 posts
  • Weekly Top Seller
  • 7 Years of Membership
  • Featured Item
  • Author Level 5
+9 more
tiam
says

Thanks a lot for the help I really appreciate it!

I must be stupid… I still get undefined when tracing the variables

outside the declaration I did trace (start_var)

this is my code now

var start_var:String; var about_var:String;

trace (about_var)

settingXML = new XML ; settingXML.ignoreWhite = true; settingXML.onLoad = function(loaded:Boolean) { if (loaded) { }

var dub = this.firstChild;
var setting = dub.attributes;
var start_var = setting.start;
var about_var = setting.about;
var portfolio_var = setting.portfolio;        
var contact_var = setting.contact;

trace(settingXML.loaded) settingXML.load(“settings.xml”);

}
675 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • Weekly Top Seller
+7 more
dexterous
says
I still get undefined when tracing the variables

Tiam,

You must try to access or trace it AFTER your onload function is executed.

You can do one of the following:

In the last line inside the onLoad function, call another function and try to trace it there.

OR simply. Put these actions on frame 1 – add a stop() action.

In the onLoad function last line – play(), in the second frame try to trace.

HTH .

8176 posts
  • Author Level 6
  • Trendsetter
  • Weekly Top Seller
  • Community Superstar
+8 more
doru
says
I must be stupid… I still get undefined when tracing the variables

try give the variables some default value.

instead

var start_var:String;
var about_var:String;
trace(about_var); //nothing there :) yeap you get undefined

try

var start_var:String = "some text";
var about_var:String = "some text";
trace(about_var); //you get "some text"

and inside the function use only

start_var = "some other text";
about_var = "some other text";
trace(about_var); //inside the function or outside you get - "some other text"

edit: use ” < code … bla bla in the post editor,” is not working :(

335 posts
  • Weekly Top Seller
  • 7 Years of Membership
  • Featured Item
  • Author Level 5
+9 more
tiam
says

Thanks doro! But by doing that I dont get the information from the xml, or do I? :)

1313 posts
  • Affiliate Level 5
  • Author Level 7
  • Beta Tester
  • Collector Level 4
+10 more
LGLab
says

The problem is you declare your variables again inside the onLoad function by using the term “var” inside the function, which makes that var “local” or “relative”, hence you won’t be able to access it outside the onLoad function, try this:

http://pastie.org/767362

Edit: Also your xml object is not datatyped, it should be:

var settingXML:XML = new XML();

Not sure if that makes a difference as AS2 is quite tolerant :-)

335 posts
  • Weekly Top Seller
  • 7 Years of Membership
  • Featured Item
  • Author Level 5
+9 more
tiam
says

Amazing! Its working now :D

Thanks so very much for the help!!!! Really appreciated :)

by
by
by
by
by
by