Image

Imagedaitengu wrote in Imageflashdev

Help

Ok. Now I cannot seem to get my generated text fields to work. I have attached the code behind the cut. This is my entire code that I have gone back and tried to rework, although it still isn't finished. I am trying to dynamically build a SWF from a XML. Anyway without further ado.

~C

//*********  1. DOCUMENT MOVIE, AUTHOR, HISTORY  ***************************//
/*
   Movie:       Dynamic flash_unit launch
   Description: A shell FLA for dynamic generation of slides based on a XML and loading external SWFs and Jpgs. 
   Author:      CW
   History:
      v 1.30    2007/03/02  Beginning Frame Work for Primary Flash Unit.
                            Should load all graphics and info from an external source.
*/
////
/*********  2. IMPORT CLASSES  ********************************************/
////
// Importing the XPathAPI class
import mx.xpath.XPathAPI;
////
/*********  3. DECLARE AND INITIALIZE VARIABLES  **************************/
////
_global.easeType = mx.transitions.easing.None.easeNone;
_global.introSize = 0;
////
// Declaring Arrays to be filled by XML
_global.slideName = new Array();
_global.imageLocation = new Array();
_global.Headline = new Array();
_global.subHead = new Array();
_global.prodDescription = new Array();
_global.price = new Array();
_global.prodLink = new Array();
////
/*********  4. DEFINE FUNCTIONS *******************************************/
////
function startIntro() {
    // Creates an empty MovieClip named "introMC"
    this.createEmptyMovieClip("introMC", 999);
    introMC.createEmptyMovieClip("introContainer", 1000);
    // Use a MovieClipLoader to load intro into the clip introMC
    var clipLoader = new MovieClipLoader();
    // Set up an object to use as a listener
    var loadListener:Object = new Object();
    // Set Up initial progressBar starting Width;
    progressBarStartWidth = 5;
    introMC.attachMovie("preLoadBar", "progress_bar", introMC.getNextHighestDepth());
    introMC.attachMovie("preLoadBorder", "progress_border", introMC.getNextHighestDepth());
    if (_global.introSize == 356) {
        // Center preloader bar for 315 wide stage
        introMC.progress_border._x = 85;
        introMC.progress_border._y = 160;
        introMC.progress_bar._x = 85;
        introMC.progress_bar._y = 160;
    } else if (_global.introSize == 600) {
        // Center preloader bar for 600 wide stage
        introMC.progress_border._x = 180;
        introMC.progress_border._y = 160;
        introMC.progress_bar._x = 180;
        introMC.progress_bar._y = 160;
    }
    introMC.progress_bar._xscale = progressBarStartWidth;
    // Set up a callback triggered when loading begins to add a progress bar to the parent MovieClip
    loadListener.onLoadStart = function(targetMC:MovieClip) {
        // Set initial position and size of the progress bar
        // Note that the rest of the bar's properties will be defined as
        // required on loading so we do not need to set them.
    };
    // Set up a callback triggered whenever loading progresses
    // to update the progress bar's appearance
    loadListener.onLoadProgress = function(targetMC:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void  {
        introMC.progress_bar._xscale = ((bytesLoaded/bytesTotal)*100);
    };
    ////
    // Listens for the loading to be complete
    loadListener.onLoadComplete = function(targetMC) {
        slidePopulate();
        introMC.progress_bar._xscale = (bytesLoaded/bytesTotal)*100;
        // Begin Tween fade of progress bar
        fadeTween = new mx.transitions.Tween(introMC.progress_bar, "_alpha", easeType, 100, 0, .25, true);
        fadeTween = new mx.transitions.Tween(introMC.progress_border, "_alpha", easeType, 100, 0, .25, true);
        fadeTween.onMotionFinished = function() {
            // Removes progress bar
            introMC.progress_bar.removeMovieClip();
            introMC.progress_border.removeMovieClip();
        };
    };
    // Install the listener
    clipLoader.addListener(loadListener);
    // Begin asynchronous loading
    clipLoader.loadClip(_global.introLink.firstChild.nodeValue, introMC.introContainer);
    ////
}
////
function closeIntro() {
    // Fades the intro Movie Clip out once it has ended.
    fadeTween = new mx.transitions.Tween(introMC, "_alpha", easeType, 100, 0, .25, true);
    fadeTween.onMotionFinished = function() {
        // Remove the intro Movie Clip
        introMC.removeMovieClip();
    };
}
////
function slidePopulate() {
    // Establishing the Text Format Options for use in this function
    // Headline
    var Head1:TextFormat = new TextFormat();
    Head1.color = 0xC188AC;
    Head1.underline = false;
    Head1.align = "left";
    Head1.font = "DIN-Medium";
    Head1.size = 18;
    // SubHead
    var subHeadline:TextFormat = new TextFormat();
    subHeadline.color = 0xC188AC;
    subHeadline.underline = false;
    subHeadline.align = "left";
    subHeadline.font = "DIN-Regular";
    subHeadline.size = 14;
    // Product Copy
    var productFmt:TextFormat = new TextFormat();
    productFmt.color = 0xC188AC;
    productFmt.underline = false;
    productFmt.align = "center";
    productFmt.font = "DIN-Bold";
    // Price Format
    var priceFmt:TextFormat = new TextFormat();
    priceFmt.color = 0x000000;
    priceFmt.underline = false;
    priceFmt.align = "center";
    priceFmt.font = "DIN-Black";
    // Previous and Next Button Format
    var btnFmt:TextFormat = new TextFormat();
    btnFmt.color = 0x999999;
    btnFmt.underline = false;
    btnFmt.align = "center";
    btnFmt.font = "DIN-Black";
    // RollOver Format
    var roFmt:TextFormat = new TextFormat();
    roFmt.color = 0x000000;
    roFmt.underline = false;
    roFmt.align = "center";
    roFmt.font = "DIN-Black";
    // Order Button Format
    var orderFmt:TextFormat = new TextFormat();
    orderFmt.color = 0xFFFFFF;
    orderFmt.underline = false;
    orderFmt.align = "center";
    orderFmt.font = "DIN-Black";
    ////
    // Establish initial local variables
    // J = total number of slides
    j = slideName_array.length;
    // K  = slide count;
    k = slideName_array.length-1;
    ////
    // Start the for loop to populate the _global arrays and generate the Movie Clips
    for (i=0; i<j; i++) {
        ////
        // Push the value of XML nodes into the global arrays
        _global.slideName.push(slideName_array[i].firstChild.nodeValue);
        _global.imageLocation.push(imgLink_array[i].firstChild.nodeValue);
        _global.Headline.push(heading_array[i].firstChild.nodeValue);
        _global.subHead.push(subHeading_array[i].firstChild.nodeValue);
        _global.prodDescription.push(productCopy_array[i].firstChild.nodeValue);
        _global.price.push(price_array[i].firstChild.nodeValue);
        _global.prodLink.push(slideLink_array[i].firstChild.nodeValue);
        ////
        // Create Main Slides
        this.createEmptyMovieClip(slideName[i], i);
        // Populate the Main Slide with all sub-movieClips
        // Had to target the slide names with associative array syntax
        ////
        // Generates the Headline Text Field
        _root[slideName[i]].createTextField("prodHead", 10, 2, .3, 150, 38);
        // Generates the Headline Text Field
        _root[slideName[i]].prodHead.type = "dynamic";
        _root[slideName[i]].prodHead.html = true;
        _root[slideName[i]].prodHead.multiline = true;
        _root[slideName[i]].prodHead.selectable = false;
        _root[slideName[i]].prodHead.wordWrap = true;
        _root[slideName[i]].prodHead.htmlText = Headline;
        _root[slideName[i]].prodHead.setTextFormat(Head1);
        _root[slideName[i]].prodHead.embedFonts = true;
        ////
        // Generates the gradient bar in the top left corner of the product image
        _root[slideName[i]].createEmptyMovieClip("gradient_mc", 0);
        // Draw gradient
        with (_root[slideName[i]].gradient_mc) {
            colors = [0xFFFFFF, 0xFFFFFF];
            alphas = [100, 0];
            ratios = [0, 0xFF];
            matrix = {matrixType:"box", x:1.5, y:1.5, w:180, h:50, r:(0/180)*Math.PI};
            beginGradientFill("linear", colors, alphas, ratios, matrix);
            movieTo(1.5, 1.5);
            lineTo(180, 1.5);
            lineTo(180, 40);
            lineTo(1.5, 40);
            lineTo(1.5, 1.5);
            endFill();
        }
        // Generates the image holder slide
        _root[slideName[i]].createEmptyMovieClip("image", -5);
        // Loads the images into the "image" clip with a preloader
       
    }
}
////
/*********  5. CALL THE INIT FUNCTION TO START THE MOVIE  *****************/
////
// Establishes new XML object
var myXML = new XML();
// Ignores White Space in the XML
myXML.ignoreWhite = true;
// Actions taken once the XML loads successfully
myXML.onLoad = function(success) {
    ////
    if (success) {
        ////
        // Retrieves names of Slides
        var slidePath:String = "/main/slide/slideName";
        slideName_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, slidePath);
        ////
        // Retrieves path to Slide Images
        var imgPath:String = "/main/slide/imgLocation";
        imgLink_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, imgPath);
        ////
        // Retrieves Path to Slide Headings
        var headingPath:String = "/main/slide/heading";
        heading_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, headingPath);
        ////
        // Retrieves Path to Slide SubHeadings
        var subHeadingPath:String = "/main/slide/subHead";
        subHeading_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, subHeadingPath);
        ////
        // Retrieves Slide Product Description
        var productCopyPath:String = "/main/slide/barCopy";
        productCopy_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, productCopyPath);
        ////
        // Retrieves Slide Product Price
        var pricePath:String = "/main/slide/priceCopy";
        price_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, pricePath);
        ////
        // Retrieves Slide Product Link
        var linkPath:String = "/main/slide/itemLink";
        slideLink_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, linkPath);
        ////
        // Retrieves Index Button Path to Load Index Button
        var indexPath:String = "/main/index/imgLocation";
        var indexLink = mx.xpath.XPathAPI.selectSingleNode(this.firstChild, indexPath);
        ////
        // Retrieves the path to the Intro if applicable
        var introPath:String = "/main/introLoc";
        _global.introLink = mx.xpath.XPathAPI.selectSingleNode(this.firstChild, introPath);
        ////
        // Retrieve the Toggle Status for the Intro
        var ToggleNode:String = "/main/introToggle";
        var ToggleSwitch = mx.xpath.XPathAPI.selectSingleNode(this.firstChild, ToggleNode);
        ////
        // Retrieve the Intro Size
        var sizeNode:String = "/main/introSize";
        var sizeSwitch = mx.xpath.XPathAPI.selectSingleNode(this.firstChild, sizeNode);
        ////
        if (sizeSwitch.firstChild.nodeValue == "356") {
            _global.introSize = 356;
        } else if (sizeSwitch.firstChild.nodeValue == "600") {
            _global.introSize = 600;
        }
        // If the intro value equals active then it calls the Intro funtion                
        if (ToggleSwitch.firstChild.nodeValue == "active") {
            startIntro();
            // Call to startIntro Function
        } else if (ToggleSwitch.firstChild.nodeValue == "inactive") {
            // If the intro value equals inactive then it calls the slidePopulate function
            slidePopulate();
        }
    }
};
// Loads the XML
myXML.load('content/content.xml');
////
// Stops the timeline so it does not keep cycling
stop();