dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: on (press)...

  1. #1
    Junior Member
    Join Date
    Aug 2005
    Posts
    5

    on (press)...

    I have an xml file that looks, kind of like this:

    Code:
    city>
      police> Some text on police.../police>
      fire>Some text on fire dept.../fire>
      law>Some text on laws.../law>
    /city>
    I took out here the less then sign, because the tags would not display

    This is a short example, I have a paragraph or two about each.

    I have some buttons in my movie, and on press of the police button the police section should display in the text box, on press of the fire button the fire...

    How can I set this up?
    Last edited by Suchy; 09-05-2005 at 10:07 AM.

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    3 Steps:

    Read in the Xml into Flash.
    Loop through the Xml looking for police, fire, law.
    Insert text into appropriate movie clip locations.

    Which part are you having trouble with?

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  3. #3
    Junior Member
    Join Date
    Aug 2005
    Posts
    5
    First of all I am having troubles setting up the script to load the xml on a press of a button.
    I tried to do this in many ways and searched for it on goolge, but could not find anything.

    Could you provide an example, great thanks in advance.

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    This is a short example, I have a paragraph or two about each.
    Curious...how many departments are to be listed...rough idea.

    If many, maybe you should bust this into 2 stages. The first to load the list of departments:

    Lets say this main loader xml was named "Main.xml"

    PHP Code:
    <?xml version="1.0"?>
    <city>
    <cityItem name="Police Department" short="police"></cityItem>
    <cityItem name="Fire Department" short="fire"></cityItem>
    <cityItem name="Waste Management" short="waste"></cityItem>
    <cityItem name="Public Records" short="public"></cityItem>
    <cityItem name="Permits" short="permit"></cityItem>
    </city>
    The "short" name are the names of seperate xml files dedicated to each department. Send the short name to an offstage textfield and advance the movie to the next frame sequence (16-20). So if i loaded the below and stopped on frame 15

    using:

    menuXML = new XML();
    menuXML.ignoreWhite = true;
    menuXML.onLoad = function(success) {
    if (success) {
    mainItem = this.firstChild.childNodes;
    for (var i=0; i<mainItem.length; i++) {
    item = list.duplicateSprite("clip" + i, i);
    item._x = 293;
    item._y = 16*i;
    item.mainlink.text = mainItem[i].attributes.name;

    item.short = mainItem[i].attributes.short;

    item.onPress = function() {


    _root.textholder = this.short;
    _root.gotoandplay(16);
    };

    }
    }
    };
    menuXML.load("Main.xml");
    }

    Then when we advance (frame 16), the short name that gets sent to the textholder text field gets picked up by the second stage to load the correct department's xml which is constructed say like this (example named police.xml on save...all would be built like this and saved with the short name prefix):

    PHP Code:
    <?xml version="1.0"?>
    <city>
    <cityItem text="some really long description here" link="somelink here"></cityItem>
    </city>
    On say about frame 20 read that textholder and load the short name xml:

    menuXML = new XML();
    menuXML.ignoreWhite = true;
    menuXML.onLoad = function(success) {
    if (success) {
    mainItem = this.firstChild.childNodes;
    for (var i=0; i<mainItem.length; i++) {
    item = list.duplicateSprite("clip" + i, i);
    item._x = 293;
    item._y = 16*i;
    item.maintext.text = mainItem[i].attributes.text;
    item.link = mainItem[i].attributes.link;


    }
    }
    };
    menuXML.load(""+_root.textholder+".xml");
    }


    Or something along this line. Otherwise you may end up loading a huge data stream since the xml file is massive with all items and descriptions in one.

    No matter what you decide on, remember the attributes that carry the data are not just for things displayed to the end user. You can send in strings and integers that YOU USE for YOUR PURPOSES injected into dynamic commands, mouseovers, frame calls, createTextField dimensions....etc. Always think out of the box with XML
    Last edited by Chris_Seahorn; 09-06-2005 at 01:57 AM.

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