dcsimg
A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: simple AS help

  1. #1
    Junior Member
    Join Date
    Jun 2003
    Posts
    12

    simple AS help

    This should be easy but I'm have a hard time figuring it out. I have some acrionscript calling info from an XML file. That all works good and fine, thanks to the great help I have found on this message board! The problem is when I make the dynamic text box in to a movie clip so it moves around it no longer display the text cause it's no longer on the _root. How do I get that clip to call to the AS back on the root? thanks.

  2. #2
    ask me one on fish..not flash
    Join Date
    Oct 2002
    Location
    southern u.k.
    Posts
    495
    give the movie clip an instance name and then change all the references to it to include the instance name.

    so if you call your movie clip "mymovieclip"

    it will be referred to as

    _root.mymovieclip.do some action to it.

    hope that helps a little

    gary
    I bought a Ouija board. The pointer spelled out 'You don't actually believe in this crap, do you

  3. #3
    Junior Member
    Join Date
    Jun 2003
    Posts
    12
    Thanks for the reply but...
    nothing really refers the the movie clip itself, It's the movie clip im trying to get to refer back to the first frame on the main movie.

    here's my AS on the main movie

    PHP Code:
    myXML = new XML()
    myXML.onLoad showXML;
    myXML.load("test.xml");
    myXML.ignoreWhite true;

    function 
    showXML(success){
        if(
    success == true) {
            
    rootNode myXML.firstChild;
            
    showText()
        }
    }

    function 
    showText(newText){
        
    txtBox rootNode.firstChild.attributes.title;

    txtBox is the variable name of the dynamic text box that is in the movie clip. Thanks

  4. #4
    ask me one on fish..not flash
    Join Date
    Oct 2002
    Location
    southern u.k.
    Posts
    495
    ok so the following line


    -------------------------
    function showText(newText){
    txtBox = rootNode.firstChild.attributes.title;
    -------------------------

    is where the text is placed into the dynamic text box
    but the text box does not exist on the _root timeline. it is now in a movieclip and you need to do what i said and change the as to something like

    ------------------------
    function showText(newText){
    _root.mymovieclip.txtBox = rootNode.firstChild.attributes.title;
    ------------------------

    or give the text box an instance name AND the mc an instance name, then put the text directly into the dynamic text box

    ------------------------
    function showText(newText){
    _root.mymovieclip.mydynamictextbox.text =
    rootNode.firstChild.attributes.title;
    ------------------------

    i guess the thing i am trying to say is that your function is operating on the _root and your textbox is not there so it will never put the text into the box. you have to name the mc and (poss) the textbox so that you can reference them in the function.

    that way flash will know exactly what you want it to do.

    phew....what a reply....lol

    try it see what happens. when i am doing stuff like this i use the insert target button to "find" my target. then i watch the values using the debug tool.

    cheers

    gary
    I bought a Ouija board. The pointer spelled out 'You don't actually believe in this crap, do you

  5. #5
    Junior Member
    Join Date
    Jun 2003
    Posts
    12
    I thought thats what you were trying to say but wasn't sure. Thanks a bunch for the help, Ill give it a try and let you know.

  6. #6
    Junior Member
    Join Date
    Jun 2003
    Posts
    12
    Ok I now have this for my code

    PHP Code:
    myXML = new XML()
    myXML.onLoad showXML;
    myXML.load("test.xml");
    myXML.ignoreWhite true;

    function 
    showXML(success){
        if(
    success == true) {
            
    rootNode myXML.firstChild;
            
    showText()
        }
    }

    function 
    showText(newText){
        
    _root.myClip.txtBox.text rootNode.firstChild.attributes.title;

    ... and I have txtBox as the instance name for the dynamic text box. and now when I run the movie it displays "_level0.myClip.txtBox"

    also if I dont put txtBox in for the instance name and for the Var: then nothing shows... see anything wrong or any Ideas? Thanks!

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    when I run the movie it displays "_level0.myClip.txtBox"
    this happens when you have the same instance name and variable name for the textfield, and then scope variables to the textfield's instance name...still with me ??

    use - with variable name ONLY
    _root.myClip.txtBox = rootNode.firstChild.attributes.title;

    or - with instance name ONLY
    _root.myClip.txtBox.text = rootNode.firstChild.attributes.title;


    hth

  8. #8
    Junior Member
    Join Date
    Jun 2003
    Posts
    12
    Yeah, I thought thats why it was giving me that output, I had ran in to that before when working with dynamic text. However either way I try it - with a varible or an instance alone im getting no out put at all. Should I have an action in the movie clip it self that calls back to the _root level? Thanks

  9. #9
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try a different approach,
    code:
    myXML = new XML()
    myXML.onLoad = showXML;
    myXML.load("test.xml");
    myXML.ignoreWhite = true;

    function showXML(success){
    if(success == true) {
    rootNode = myXML.firstChild;
    display = rootNode.firstChild.attributes.title;
    showText(display);
    }
    }

    function showText(newText){
    _root.myClip.txtBox.text = newText;
    }

    does this help ?

  10. #10
    Junior Member
    Join Date
    Jun 2003
    Posts
    12
    Good Idea! I'll give it a shot and let you know.

  11. #11
    Junior Member
    Join Date
    Jun 2003
    Posts
    12
    OK, maybe this isn't so 'simple' cause that's not working either... I can get it to work if I put an action in the movie clip it self that calls the XML file and what not again, but I wanted to aviod that to keep the file size down and make it easy to edit if I ever need to... grr... i'm so stumped, I do appreciate all the help by the way.

    I attached my FLA if you feel like taking a look.
    Attached Files Attached Files

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    your myXML.onLoad passes the text variable to the textfield in the movieclip on frame 1.
    but your movieclip does not appear until frame 5, so it will not receive it.
    alter your code -

    Frame#1-
    myXML = new XML()
    myXML.onLoad = showXML;
    myXML.load("test.xml");
    myXML.ignoreWhite = true;

    function showXML(success){
    if(success == true) {
    rootNode = myXML.firstChild;
    display = rootNode.firstChild.attributes.title;
    }
    };

    function showText(newText){
    _root.myClip.txtBox.text = newText;
    };

    Frame#5 - showText(display);

    does that help ?

  13. #13
    Junior Member
    Join Date
    Jun 2003
    Posts
    12

    and we have a winner~!

    It works, Thanks a bunch a_modified_dog you da'man! here have a doughnut on me told you it was simple lol lata

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