A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Help with accessing variables within a function on xml load

  1. #1
    Junior Member
    Join Date
    Mar 2006

    Help with accessing variables within a function on xml load

    hi all, im having a problem, take a look.

    this is my xml:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    		<banner id="1" sourceFile="banner1.swf" clickurl="http://www.nsimex.com" seconds="10" />
    		<banner id="2" sourceFile="banner2.swf" clickurl="http://www.prolincmex.com" seconds="20" />
    		<banner id="3" sourceFile="banner1.swf" clickurl="http://www.google.com" seconds="30" />
    		<banner id="4" sourceFile="banner2.swf" clickurl="http://www.yahoo.com" seconds="40" />
    		<banner id="5" sourceFile="banner1.swf" clickurl="http://www.hotmail.com" seconds="50" />
    		<banner id="6" sourceFile="banner2.swf" clickurl="http://www.esmas.com" seconds="60" />
    		<banner id="7" sourceFile="banner1.swf" clickurl="http://www.f1.com" seconds="70" />
    		<banner id="8" sourceFile="banner2.swf" clickurl="http://www.cart.com" seconds="80" />
    thats ok, then my actionscript is this:
    //first we create/define the variables we are going to work with
    var bannerID = new Array();
    // XML STUFF
    //create new xml object and set ignoreWhite true.
    bannerFX_xml = new XML();
    bannerFX_xml.ignoreWhite = true;
    // if sucess we recall a function wich will be the parser of our module.
    bannerFX_xml.onLoad = function (sucess) {
    	if (sucess)	{
    //we now load our module url
    // now we define our function.
    function processBannerFX(xmlDoc_xml) {
    	nodeList = bannerFX_xml.firstChild.childNodes; 
    	nodeListLength = nodeList.length;
    	for (i = 0; i < nodeListLength;  i++) {
    		// we create an array to store our information despite of how many banners we have.
    		bannerID['id'+i] = nodeList[i].attributes.id;
    		bannerID['sourceFile'+i] = nodeList[i].attributes.sourceFile;
    		bannerID['clickUrl'+i] = nodeList[i].attributes.clickurl;
    		bannerID['seconds'+i] = nodeList[i].attributes.seconds;
    trace (bannerID['sourceFile0']);
    //Button linkage
    button.onRelease = function () {
    trace (bannerID['sourceFile0']);
    everything works fine, the thing that extrange me is that when i make the "trace" on the button action (last line of code) that works fine, but when i make the "trace" outside any function i get "undefined".

    can someone please help me?
    what im trying to do is a banner system, where you can have multiple banners, so im trying to do a "loadMovieNum(bannerID['sourceFile0'], 2);" but thats when i get the "undefined" error.

    what im doing wrong?

    thank you.

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    London, UK
    its because u are calling the trace before the xml document has loaded... u always have to make sure the xml document has been fully loaded..
    Flashmatics | Flashmatics Library (free downloads)
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    Flash Certified Developer

  3. #3
    Junior Member
    Join Date
    Mar 2006
    hehe im so embarrased..... rookie mistake

    thanks for your time and sorry for that stupid question, you are totally right.... no wonder this thing didnt worked.

    thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center