PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
can't get as2 to display second xml txt field
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: can't get as2 to display second xml txt field

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    3

    Unhappy can't get as2 to display second xml txt field

    Hi, I've got an xml banner that i'm working on. I've got the images loading fine and one txt field loading but the second txt field only loads the same node as the first and it doesn't matter what I change in the AS. I need to put buttons on the top too to point to the specific slides but i can deal with that later, right now i just want to get the second piece of txt loading.

    It's the showPrice that I can't get to work.

    This is the code in the first frame of my movie:
    Actionscript Code:
    //Load from XML File
    stop();
    //Banner
    var banners:Array = new Array();
    //Image Path
    var imagePaths:Array = new Array();
    //Link URL
    var links:Array = new Array();
    //Body Text
    var bodyTexts:Array = new Array();
    //
    var imageTime:Number;
    //
    var numberOfBanners:Number;
    //
    var isRandom:String;
    //
    var showHeader:String;
    //
    var bannersXML:XML = new XML();
    bannersXML.ignoreWhite = true;
    bannersXML.load("banners.xml");
    bannersXML.onLoad = function(success) {
        if (success) {
            trace("XML LOADED");
            imageTime = parseInt(this.firstChild.firstChild.firstChild)*1000;
            numberOfBanners = parseInt(this.firstChild.childNodes[1].firstChild);
            isRandom = this.firstChild.attributes["isRandom"];
            showHeader = this.firstChild.childNodes[2].attributes["showHeader"];
            showPrice = this.firstChild.childNodes[3].attributes["showPrice"];

            var bannerSequence:Array = new Array();
            if (isRandom == "true") {
                //Make a random sequence
                while (bannerSequence.length<numberOfBanners) {
                    newRandomNumber = random(numberOfBanners);
                    //Make sure that the random one chosen is not already chosen
                    for (var i = 0; i<=bannerSequence.length; i++) {
                        if (newRandomNumber != bannerSequence[i]) {
                            alreadyThere = false;
                        } else {
                            alreadyThere = true;
                            break;
                        }
                    }
                    //Add only random values that aren't in the array
                    if (!alreadyThere) {
                        bannerSequence.push(newRandomNumber);
                    }
                }
            } else {
                for (var i = 0; i<numberOfBanners; i++) {
                    bannerSequence.push(i);
                }
            }
        }

        //Read XML in the Random Order Chosen
        for (var i = 0; i<numberOfBanners; i++) {
            banners.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].firstChild.firstChild.toString());
            bodyTexts.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].childNodes[1].firstChild.nodeValue);
            bodyTexts2.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].childNodes[4].firstChild.nodeValue);
            imagePaths.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].childNodes[2].firstChild.nodeValue);
            //links.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].childNodes[3].firstChild.nodeValue);
        }
        play();
    };
    //Start the image counter at 0
    var imageCounter = 0;

    and this is the code in the second:

    Actionscript Code:
    stop();
    //Check to see if the banner should be reset
    if (imageCounter>=banners.length) {
        imageCounter = 0;
    }
    //Load banner image  
    var imageLoader:MovieClipLoader = new MovieClipLoader();
    imageLoader.loadClip("img/"+imagePaths[imageCounter],bannerContainer_mc);
    var loadingListener:Object = new Object();
    loadingListener.onLoadComplete = function() {
        play();
        //Display Header
        if (showHeader == "true") {
            imageText_mc.headerTxt.text = banners[imageCounter].toString();
            imageText_mc.priceTxt.text = banners[imageCounter].toString();
        } else {
            imageText_mc.headerTxt.text = "";
            imageText_mc.priceTxt.text = "";
            imageText_mc._alpha = 0;
        }
       
        //Button and Link Handling
        if (links[imageCounter] != null) {
            trace("LINK : "+links[imageCounter]);
            bannerContainer_mc.onRelease = function() {
                getURL(links[imageCounter], "_blank");
            };
        } else {
            delete bannerContainer_mc.onRelease;
        }
    };
    imageLoader.addListener(loadingListener);

  2. #2
    Junior Member
    Join Date
    Jul 2010
    Posts
    3

    Getting somewhere but still not close enough yet

    I noticed I hadn't declared showPrice in the xml file.

    Still no luck loading the right node in it yet though, I also changed the second frame code to:

    Actionscript Code:
    stop();
    //Check to see if the banner should be reset
    if (imageCounter>=banners.length) {
        imageCounter = 0;
    }
    //Load banner image  
    var imageLoader:MovieClipLoader = new MovieClipLoader();
    imageLoader.loadClip("img/"+imagePaths[imageCounter],bannerContainer_mc);
    var loadingListener:Object = new Object();
    loadingListener.onLoadComplete = function() {
        play();
        //Display Header
        if (showHeader == "true") {
            imageText_mc.headerTxt.text = banners[imageCounter].toString();
        } else {
            imageText_mc.headerTxt.text = "";
            imageText_mc._alpha = 0;
        }
       
            //Display Price
        if (showPrice == "true") {
            priceText_mc.priceTxt.text = banners[imageCounter].toString();
        } else {
            priceText_mc.priceTxt.text = "";
            imageText_mc._alpha = 0;
        }
           
            //Button and Link Handling
        if (links[imageCounter] != null) {
            trace("LINK : "+links[imageCounter]);
            bannerContainer_mc.onRelease = function() {
                getURL(links[imageCounter], "_blank");
            };
        } else {
            delete bannerContainer_mc.onRelease;
        }
    };
    imageLoader.addListener(loadingListener);

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Where are you incrementing 'imageCounter'?

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    thought i could use it in my next step, (actually it came with the source) but i also need to put a tab up per image, have the tab relative to the image change color while that image is on deck and clickable to that image when it isnt...

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