dcsimg
A Flash Developer Resource Site

Page 1 of 4 1234 LastLast
Results 1 to 20 of 61

Thread: load XML into Flash Component

  1. #1
    Member
    Join Date
    Jun 2000
    Posts
    97

    load XML into Flash Component

    Hi guys,

    Newbie still, so bare with me.

    Ok, so I have a tree loaded into flash which loads great.

    NOW!!! My task is to load xml content from the loaded Tree.xml into a component that sits on my stage which is call "my_loader"

    Can anyone guide me on how to load the XML content into the "my_loader" component from the loaded Tree.xml?

    Up until now I have just loaded seperate movies onto the stage ... What I really want is one base movie and the rest to be dynamically controlled via XML.

    Any help would be highly appreciated .... Maybe even a FLA and XML example if you can spare time or have worked with something similar.

    Thanks

    Stagehand
    Last edited by stagehand; 11-20-2007 at 08:19 AM.
    Stagehand

  2. #2
    Member
    Join Date
    Jun 2000
    Posts
    97
    Anyone?

    Believe me, I've searched and searched for this but can't find a solution.

    I can get 2 textfields working, but I need a component for at least one as it will be also using images.

    Thanks
    Stagehand

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    can you clarify -
    1 - Flash version you are using
    2 - you are using a Tree component ? How are you loading it ? What code ?
    3 - what kind of component is "my_loader" ?
    4 - what is the structure of Tree.xml ?

  4. #4
    Member
    Join Date
    Jun 2000
    Posts
    97
    Quote Originally Posted by a_modified_dog
    can you clarify -
    1 - Flash version you are using
    2 - you are using a Tree component ? How are you loading it ? What code ?
    3 - what kind of component is "my_loader" ?
    4 - what is the structure of Tree.xml ?
    OK, thanks for the reply .. here's what I'm trying. I could be way out.

    1 - Flash 8
    2 - Tree Code - Merely just a modified Flash 8 tree component

    var my_tree:mx.controls.Tree;

    var treeDP_xml:XML = new XML();
    treeDP_xml.ignoreWhite = true;
    treeDP_xml.onLoad = function(success:Boolean) {
    if (success) {
    my_tree.dataProvider = this.firstChild;
    }
    };

    treeDP_xml.load("Tree.xml");
    var treeListener:Object = new Object();
    treeListener.change = function(evt:Object) {
    var treeNode:XMLNode = evt.target.selectedItem;
    if (treeNode.attributes.src != undefined) {
    my_loader.load(treeNode.attributes.src);
    }
    };
    my_tree.addEventListener("change", treeListener);



    my_tree.addEventListener("change", treeListener);
    var lo = new Object();
    lo.change = function (event_obj)
    {
    var tree = event_obj.target;
    var sel_tn = tree.selectedNode;
    if (tree.getIsBranch(sel_tn))
    {
    var nodeAlreadyOpen_bool = tree.getIsOpen(sel_tn);
    tree.setIsOpen(sel_tn,!nodeAlreadyOpen_bool);
    }
    }
    my_tree.addEventListener('change',lo);

    3 - My_loader component is the Flash 8 mx.controls.Loader (which could be better I'm sure, if you've a suggestion). I just need something that can load text and images.

    4 - The Tree.xml code is this (which works in one instance, but will need to be addressed for two areas, this is where I'm in a daze:

    <?xml version="1.0"?>
    <tree>

    <node label="section 1">
    <node label="section 1 content 1" src="section1.xml" />
    <node label="section 1 content 2" src="section2.xml" />
    <node label="section 1 content 3" src="section3.xml" />
    <node label="section 1 content 4" src="section4.xml" />
    <node label="section 1 content 5" src="section5.xml" />
    <node label="section 1 content 6" src="section6.xml" />
    <node label="section 1 content 7" src="section7.xml" />
    <node label="section 1 content 8" src="section8.xml" />
    <node label="section 1 content 9" src="section9.xml" />
    <node label="section 1 content 10" src="section10.xml" />
    </node>
    <node label="section 1">
    <node label="section 2 content 1" src="section1.xml" />
    <node label="section 2 content 2" src="section2.xml" />
    <node label="section 2 content 3" src="section3.xml" />
    <node label="section 2 content 4" src="section4.xml" />
    <node label="section 2 content 5" src="section5.xml" />
    <node label="section 2 content 6" src="section6.xml" />
    <node label="section 2 content 7" src="section7.xml" />
    <node label="section 2 content 8" src="section8.xml" />
    <node label="section 2 content 9" src="section9.xml" />
    <node label="section 2 content 10" src="section10.xml" />
    </node>


    I really need to get this going, so if you can suggest a modification or an alternative that would be really helpful.

    Here's hoping!!

    To add. If I add a second instance of:

    treeDP_xml.load("instruct_tree.xml");
    var treeListener:Object = new Object();
    treeListener.change = function(evt:Object) {
    var treeNode:XMLNode = evt.target.selectedItem;
    if (treeNode.attributes.src != undefined) {
    my_loader2.load(treeNode.attributes.src);
    }
    };
    Changing the my_loader to my_loader2, it kinda works.... Both fields are actually filled now, but unfortunately with the same content .... So the idea is kinda there, I just need to get it so the 2 components load 2 different content.
    Last edited by stagehand; 11-21-2007 at 06:32 AM.
    Stagehand

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    on my stage i have -
    Tree component - my_tree
    Loader component - my_loader

    i have 2 xml files - Tree.xml and section1.xml
    section1.xml is a simple reference to a jpg - image1.jpg
    PHP Code:
    <?xml version="1.0"?> 
    <node>image1.jpg</node>
    selecting Section1 - section1 content1 in the Tree will
    send the xml file attribute to a new XML object.
    the new object will parse the file parameter
    and load the image into the Loader component.

    Note - Loader component can only display a SWF or JPEG file
    PHP Code:
    var my_tree:mx.controls.Tree;

    var 
    treeDP_xml:XML = new XML();
    treeDP_xml.ignoreWhite true;
    treeDP_xml.onLoad = function(success:Boolean) {
    if (
    success) {
    my_tree.dataProvider this.firstChild;
    }
    };

    treeDP_xml.load("Tree.xml");
    var 
    treeListener:Object = new Object();
    treeListener.change = function(evt:Object) {
    var 
    treeNode:XMLNode evt.target.selectedItem;
    if (
    treeNode.attributes.src != undefined) {
    loadContent(treeNode.attributes.src);
    }
    };
    my_tree.addEventListener("change"treeListener);

    function 
    loadContent(file){
    _xml = new XML();
    _xml.ignoreWhite true;
    _xml.load(file);
    _xml.onLoad = function(){
    image this.firstChild.childNodestrace(image);
    my_loader.load(image);
    };
    }; 
    hope this approach helps you on your way

  6. #6
    Member
    Join Date
    Jun 2000
    Posts
    97
    Thanks for the help oh modified dog ;o)

    However, I'm similar to a modified fish, in that I'm like a fish out of water ...

    Can I upload the files and maybe you can take a look?

    It should take you less time than it would take to boil an ostrich egg ;o)

    I just need the tree to be there working, with two things on the stage that can accept xml files with mixed content etc... I'm sure you get my drift ;o)

    I've no space to upload these files, can I do it directly on the board?
    Last edited by stagehand; 11-21-2007 at 10:27 AM.
    Stagehand

  7. #7
    Member
    Join Date
    Jun 2000
    Posts
    97
    oops
    Stagehand

  8. #8
    Member
    Join Date
    Jun 2000
    Posts
    97
    OK, here's the file, can you work your magic for me please?

    Thank you.

    I don't think for one minute I'm going to get paid for this project, but if I do I shall drop you a penny or two for your help.
    Attached Files Attached Files
    Last edited by stagehand; 11-21-2007 at 01:09 PM.
    Stagehand

  9. #9
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    not exactly sure how i can help you

    i created a temp.swf and clicked the links in the Tree component
    and temp.swf loaded to the Loader component, as specified in xml file

    as i see it, it works fine

  10. #10
    Member
    Join Date
    Jun 2000
    Posts
    97
    The thing is, I need it to load XML and not swf ...with the component I have you already said it would only hold swf or jpg files.

    I just need two holders on the stage that I can load XML into and not swf. One section click to load two XML files into two dofferent areas as it were. Left and right content.

    The XML in question will have a mixture of Images and Text .... It does work fine with loading flash files, but it's the XML I need it to load. So theres only one movie to edit, the rest being dynamically driven with XML.

    So, to sum up. Load the tree, have 2 instances on the stage that I can load an XML file for each into from one section click.

    I'm sure it's a simple thing to do if you know what you're doing, however, I'm clearly as thick as a malteser on a holiday to margate.

    Help me Obi-Wan Kenobi, you're my only hope.



    I'm not overly great at explaing things I know. For that I apologise, but if you could help me out, I'll need the following:

    1) Change the tree code to be able to load XML content from the tree insrtead of SWF. Which may already work if the component is changed to accept XML on the stage.
    2) Change the holder (component) on the stage into two components that actually load the two XML files into it and not be limited to swf and jpg.
    3) Create two ultra simple xml file with an image and a bit of text in it. Purely just to show it works when xml is called.

    I hope I've explained that ok.

    Thanks dog. I'll sort you out with a little food if I can ;o)
    Stagehand

  11. #11
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    to prevent me barking up the wrong Tree, is this scenario correct ?

    load Tree from xml
    click in tree to load secondary xml
    secondary xml points to image/text
    if so, please provide -

    the main.xml file that loads into Tree component (with xml links, not swf as above)

    an example of the xml file that contains the text and image

  12. #12
    Member
    Join Date
    Jun 2000
    Posts
    97
    Quote Originally Posted by a_modified_dog
    to prevent me barking up the wrong Tree, is this scenario correct ?

    load Tree from xml
    click in tree to load secondary xml
    secondary xml points to image/text
    if so, please provide -

    the main.xml file that loads into Tree component (with xml links, not swf as above)

    an example of the xml file that contains the text and image
    Absolutely spot on ...

    The main xml you have, all you'll need to do is change the swf to xml. It doesn't matter how it works, I just need a working example really. I don't actually have the text and image xml working properly, so it might be easier if you could just do a simple one that I can see working and then adjust accordingly.

    Someone else is actually going to be doing all the XML files content, I just need to provide them with the template as it were. Hope this makes sense?

    Let me know if you need anything.

    Thanks for this dog... HIGHLY APPRECIATED!!!!
    Stagehand

  13. #13
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    if separate xml files are not an absolute neccesity, have you considered
    keeping all data in the main xml file ?
    an example would be -
    PHP Code:
    //--on stage--
    //--Tree component - instance name -- my_tree
    //--Loader component - instance name -- my_loader
    //--TextArea component - instance name -- my_ta
    //--main timeline code--

    var my_tree:mx.controls.Tree;
    var 
    my_ta:mx.controls.TextArea;

    var 
    treeDP_xml:XML = new XML();
    treeDP_xml.ignoreWhite true;
    treeDP_xml.onLoad = function(success:Boolean) {
    if (
    success) {
    my_tree.dataProvider this.firstChild;
    }
    };

    treeDP_xml.load("Tree.xml");

    var 
    treeListener:Object = new Object();
    treeListener.change = function(evt:Object) {
    var 
    treeNode:XMLNode evt.target.selectedItem;
    if (
    treeNode.attributes.img != undefined) {
    my_loader.load(treeNode.attributes.img);
    my_ta.text treeNode.attributes.txt;
    }
    };
    my_tree.addEventListener("change"treeListener); 
    Tree.xml file -
    PHP Code:
    <?xml version="1.0"?> 
    <tree>
    <node label="section 1">
    <node label="section 1 content 1" img="image1.jpg" txt="some text for section 1" />
    <node label="section 1 content 2" img="image2.jpg" txt="some text for section 2" />
    <<<snip for brevity>>>
    </node>
    </tree>

  14. #14
    Member
    Join Date
    Jun 2000
    Posts
    97
    Great idea, but from what I can gather there will be ALOT of XML files .... Probably over 1000 ....Could be less, could be more.

    Hence why I just need the core to work ...

    Originally I just thought of doing an SWF for all the seperate XML files, until I heard just how much content this could have over the next few years, lol...

    Therefore Mr Dog sir, if you could bail me out on this one the earth where you tread would be kissed ;o)
    Stagehand

  15. #15
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    main.xml as per your original
    example of section1.xml -
    PHP Code:
    <?xml version="1.0"?> 
    <node img="image1.jpg" txt="text for section1" />
    code in Flash to load section1.xml from selection in Tree
    info. from section1.xml loads image to Loader and text to TextArea
    PHP Code:
    var my_tree:mx.controls.Tree;
    var 
    my_ta:mx.controls.TextArea;

    var 
    treeDP_xml:XML = new XML(); 
    treeDP_xml.ignoreWhite true
    treeDP_xml.onLoad = function(success:Boolean) { 
    if (
    success) { 
    my_tree.dataProvider this.firstChild

    }; 

    treeDP_xml.load("Tree.xml"); 

    var 
    treeListener:Object = new Object(); 
    treeListener.change = function(evt:Object) { 
    var 
    treeNode:XMLNode evt.target.selectedItem
    if (
    treeNode.attributes.src != undefined) {
    trace(treeNode.attributes.src
    loadContent(treeNode.attributes.src); 

    }; 
    my_tree.addEventListener("change"treeListener); 

    function 
    loadContent(file){ 
    _xml = new XML(); 
    _xml.ignoreWhite true
    _xml.load(file); 
    _xml.onLoad = function(){ 
    image this.firstChild.attributes.imgtrace(image); 
    txt this.firstChild.attributes.txttrace(txt); 
    my_loader.load(image);
    my_ta.text txt;
    }; 
    }; 

  16. #16
    Member
    Join Date
    Jun 2000
    Posts
    97
    Sir, you are a true gentlemen.

    The only slight change if I may be so bold would be that both sections will have mixed contet.

    From the tree I would load both Text And Image into Both fields from section1.xml ..

    Pretty much like this:
    http://www.actionscript.org/resource...004/Page1.html

    one in each field


    Do I just change the tree code in flash or can the guy writing the XML work that from what I give him?

    Now I know where the phrase 'The Dogs Bollox' comes from. Dude, you're the NUTS!!!
    Stagehand

  17. #17
    Member
    Join Date
    Jun 2000
    Posts
    97
    Ooh, and we've lost the open command if you click on the actual section. Only the arrows open the section. Oh, and the clips on the stage seem to be buttons that close the menu, which I don't really want.

    Fear not, I will leave you alone soon dog ;o) I do apologise.

    I am now off on a hunt to find out how to get rid of the border and whitespace from the TextArea component ;o)

    Woo Hoo, just got rid of the border, just the background colour to remove now ;o)
    Last edited by stagehand; 11-23-2007 at 10:47 AM.
    Stagehand

  18. #18
    Member
    Join Date
    Jun 2000
    Posts
    97
    You still about Mr Dog?

    Can you help me just complete this last bit please?

    Thanks
    Stagehand

  19. #19
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    we've lost the open command
    has it worked before ? if so, look at your back-up file, and modify to suit
    (you do keep back-ups, i hope. i do )

    clips on the stage seem to be buttons
    absolutely no idea, sorry

    use styles to modify the TextArea, (instance name - my_ta)
    PHP Code:
    my_ta.setStyle"borderStyle""none");
    my_ta.setStyle"backgroundColor""0x000000" );
    my_ta.setStyle"color""0xFFFFFF" );

    my_ta.text "blah blah blah"

  20. #20
    Member
    Join Date
    Jun 2000
    Posts
    97
    Thanks dog, got the formating pretty much.

    Am looking for a way to put a dividing line in between sections.... Impossible to find ... borderStyle and borderColor were a doddle, but getting a line in between the sections seems impossible.

    Also, off hand, you don't have any idea how I can use and accordion effect do you? as in, when one section opens the other closes? .... Oh, and the smooth sliding thing.

    I take it the image/text content isn't possible then?

    Thanks dog
    Stagehand

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