A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: XML Buttons that can open images dynamically!!! Help!!!!!

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    XML Buttons that can open images dynamically!!! Help!!!!!

    I have created an xml file that lists a number of images. Each of those images has a unique file name and title that marks it, the title will be placed in the button so the button can relate to which particular image it is supposed to open.

    I have created a loop in flash that will cycle through the xml document and create buttons based on how many images are listed in the XML file. If I have 10 images it will create 10 buttons with the unique name described in the xml file. If i have 100 it will create 100 instances and so on.

    PROBLEM:

    I cannot program the newly created buttons to open their corresponding image, because the buttons do not know what their instance name is. The instance names are created dynamically at run time. SO it seems impossible for me to assign the correct link to the correct button without physically typing it myself inside the flash file...

    that defeats the purpose of having a dynamic menu in the first place.

    Here is my xml file in this case I am only using 3 images :

    <?xml version="1.0" encoding="UTF-8"?>

    <menu>

    <project>
    <title>Encore Music Forum</title>
    <image>picture1.jpg</image>

    </project>

    <project>
    <title>RIM - Blackberry Bold</title>
    <image>picture2.jpg</image>

    </project>

    <project>
    <title>Bak Magazine feature</title>
    <image>picture3.jpg</image>

    </project>

    </menu>


    Here is my actionscript (2.0)

    xStart = 10

    yStart = 24;

    bWidth = 82;

    bHeight = 18;

    var menuXML = new XML();
    menuXML.ignoreWhite = true;
    menuXML.onLoad = loadData;
    menuXML.load("menu.xml");

    function loadData() {

    titles = [];//array to hold the title of each image and button name
    image =[];// array to hold the location of each image

    for (i=0; i<this.firstChild.childNodes.length; i++) {

    titles[i] = this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
    image[i] = this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
    var b = _root.attachMovie("button", titles[i], i);
    b._x = xStart;
    b._y = yStart + (bHeight*i);
    b.txt = titles[i];


    b.onPress = function(){

    loadMovie("picture1.jpg","pages");

    }


    }
    }


    As have it designed right now each button opens the same exact image. how can I make it so each button opens its corresponding image? I do not want to hard code it into flash, instead i want the buttons to know which image they should open based on number...

    ex. button26 opens picture26


    HELP!!!!

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    pass a variable to the attached clip to hold its jpg name -
    b.image = image[i];

    refer to the name in the button action with -
    loadMovie(this.image,"pages");

    PHP Code:
    xStart 10 

    yStart 
    24;

    bWidth 82;

    bHeight 18;

    var 
    menuXML = new XML();
    menuXML.ignoreWhite true;
    menuXML.onLoad loadData;
    menuXML.load("buttons.xml");

    function 
    loadData() {

    titles = [];
    image =[];

    for (
    i=0i<this.firstChild.childNodes.lengthi++) {

    titles[i] = this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
    image[i] = this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
    var 
    _root.attachMovie("button"titles[i], i);
    b._x xStart;
    b._y yStart + (bHeight*i);
    b.txt titles[i];
    b.image image[i];

    b.onPress = function(){
    loadMovie(this.image,"pages");
    };

    }


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