A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Random XML - High Score?

  1. #1
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315

    Random XML - High Score?

    Ok - I have an idea, and was wondering how this could be done, without using PHP - XML only.

    I have a duck-shooting game that works well and ads up the points for each duck shot (whatever the point value). Now, could I pull in a randomized XML file and feed the point value to ducks. THEN when a player shoots a duck it randomizes the number and adds them up for a total?

    Can this be done? I'm not sure how I would add posted XML values after a duck has been hit... Any suggestions?

    OR is it easy to just randomize it within flash?

  2. #2
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Gents... I broke down and used PHP (pretty much only way). I've randomized the numbers through an external XML file. When a duck is shot, the random xml number is displayed (in a text field). No need to total the numbers, because I'm exporting 3 of the text fields to an NEW XML file. Everything works, except I'm getting an 'undefined' when creating/exporting the new XML.

    I'm thinking this is a larying issue - because the random number is in an MC, and the random numbers export the new XML nicely when I test the text area within the main timeline. I've tried _root; _parent; _level0 with no avail.

    Any ideas?

    Code for random number load:
    PHP Code:
    // on stage - 3 dynamic textfields 
    // instance names - text01, text02, text03 (and so on)

    TL this// reference to main timeline

    _xml = new XML(); 
    _xml.ignoreWhite true
    _xml.load("duck.xml"); 

    _xml.onLoad = function(){ 
    nodes this.firstChild.childNodes
    len nodes.length
    for(var 
    n=0;n!=len;n++){ 
    id nodes[n].attributes['id']; trace(id); 
    txt nodes[n].firstChild.nodeValuetrace(txt); 
    TL["text"+id].text txt

    }; 
    and the code for the export:
    PHP Code:
    btn_send.onRelease = function()

    writeXML(); 
    };

    function 
    writeXML(){
    sv = new LoadVars();

    sv.text01 text01.text;
    sv.text02 text02.text;
    sv.text03 text03.text;

    sv.sendAndLoad("writeXML.php",sv,"POST");
    };

    stop(); 

  3. #3
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Anyone? Ideas?

  4. #4
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    trace text01.text inside of your loadVars for sending the vars. Double check your you're php for $_REQUEST['text01']; or $_POST['text01']; Make sure it's spelled right. Um, that's about all I can tell with what you've got.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  5. #5
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    mneil, thanks for the response. I've been looking at this for 2 days now. How do I do a trace? Never done one before.

    Here's my PHP code:

    PHP Code:
    <?php
    $desc 
    $_POST['desc'];
    $game $_POST['game'];
    $points $_POST['points'];

    $doc domxml_new_doc('1.0');
    $root $doc->add_root('members');

    $member $root->new_child('member','');

    $member->new_child('text01',$text01);
    $member->new_child('text02',$text02);
    $member->new_child('text03',$text03);

    $fp = @fopen('../games/winner.xml','w');
    if(!
    $fp) {
        die(
    'Error cannot create XML file');
    }
    fwrite($fp,$doc->dumpmem());
    fclose($fp);
    ?>

  6. #6
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    no joke? Let me help. If that php is the writeXML.php script then I think I see one problem already, but I'm still new to php and don't quite understand the use of properties and objects in it, nor scope. But, I know how to make it work when I need it, so lets try re-arranging it. First, trace out text01 in flash to see that's its okay.

    Change:
    PHP Code:
    function writeXML(){
    sv = new LoadVars();

    sv.text01 text01.text;
    sv.text02 text02.text;
    sv.text03 text03.text;

    sv.sendAndLoad("writeXML.php",sv,"POST");
    }; 
    TO:
    PHP Code:
    function writeXML(){
    sv = new LoadVars();
    trace('text01.text= '+text01.text);//traces in the output panel the contents of the textbox
    sv.text01 text01.text;
    sv.text02 text02.text;
    sv.text03 text03.text;

    sv.sendAndLoad("writeXML.php",sv,"POST");
    }; 
    As long as the contents of that textbox show up in the output panel in the flash ide then your content is being sent. So, on to the php script then. But, I don't know that the php you've showed me is the right one so either tell me that it is writeXML.php or post that code too.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  7. #7
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Tried the addition of your tracer, and it didn't seem to do much. The file writes, but the text still comes up as undefinded.

    The output works perfectly when I have the [text00] areas in the main timeline. When I move them into my MCs, the xml outpute areas come up as undefined. I would post the file, but the grunt of the code is what you see.

    I'm still thinking it's a root issue. I'm AS that writes the the XML is in the main timeline, but the dynamic txt areas are in the MC's....

    Any ideas? I refuse to give up on this idea.

  8. #8
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    whatever the instance name is of the mc that you move the textboxes into should precede the name of the textboxes themselves. So this
    PHP Code:
    sv.text01 text01.text;
    sv.text02 text02.text;
    sv.text03 text03.text
    might look like

    PHP Code:
    sv.text01 someMC.text01.text;
    sv.text02 someMC.text02.text;
    sv.text03 someMC.text03.text
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  9. #9
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Hmmmm it's still writing the file, however here's what I get:

    PHP Code:
      <?xml version="1.0" ?> 
    - <members>
    - <member>
      <text01>undefined</text01> 
      <text02>undefined</text02> 
      <text03 /> 
      </member>
      </members>
    code output:
    PHP Code:
    btn_send.onRelease = function()

    writeXML(); 
    };

    function 
    writeXML(){
    sv = new LoadVars();

    trace('text01.text= '+text01.text);

    sv.text01 baddi1.text01.text;
    sv.text02 jugs.text02.text;

    sv.sendAndLoad("duck.php",sv,"POST");
    };

    stop(); 
    I must be missing something...??

  10. #10
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    take note of NOTES(1 & 2);
    PHP Code:
    function writeXML(){ 
    sv = new LoadVars(); 

    sv.text01 baddi1.text01.text
    sv.text02 jugs.text02.text

    //NOTE(1) - if loadvars object sends variables text01, text02

    sv.sendAndLoad("duck.php",sv,"POST"); 
    }; 
    PHP Code:
    //NOTE(2) - then php needs to receive text01, text02
    <?php 
    $text01 
    $_POST['text01']; 
    $text02 $_POST['text02']; 

    $doc domxml_new_doc('1.0'); 
    $root $doc->add_root('members'); 

    $member $root->new_child('member',''); 

    $member->new_child('text01',$text01); 
    $member->new_child('text02',$text02); 

    $fp = @fopen('../games/winner.xml','w'); 
    if(!
    $fp) { 
        die(
    'Error cannot create XML file'); 

    fwrite($fp,$doc->dumpmem()); 
    fclose($fp); 
    ?>

  11. #11
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Hi Mod Dog! Congrats on all the posts! Thanks for bouncing into this topic.
    I went ahead and fixed the PHP (feeling stupid i didn't catch this). However, it still didn't work. Code is writing the file and giving me the same xml output.

    Are we sure this isn't a layering issue?

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    a layering issue? do you mean a PATH issue ?

    Check if that is the case HERE -
    PHP Code:
    function writeXML(){ 
    sv = new LoadVars(); 

    sv.text01 baddi1.text01.text
    sv.text02 jugs.text02.text

    //output HERE
    trace(sv); // is output correct ?

    sv.sendAndLoad("duck.php",sv,"POST"); 
    }; 

  13. #13
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Yes - the out put is correct. It's creating the XML file, but i'm getting:

    <?xml version="1.0" ?>
    - <members>
    - <member>
    <text01>undefined</text01>
    <text02>undefined</text02>
    </member>
    </members>

    Works perfect when I bring the text fields out to the main time line, but I need them to stay in the MC's behind the ducks.

  14. #14
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    if the output is correct, it should not matter which timeline they come from.

    test the php return with this -

    PHP Code:
    function writeXML(){ 
    sv = new LoadVars(); 
    sv.text01 baddi1.text01.text
    sv.text02 jugs.text02.text
    sv.sendAndLoad("duck.php",sv,"POST"); 
    sv.onLoad = function(){
    trace("var1="+this.var1);
    trace("var2="+this.var2);
    };
    }; 
    add two lines to the php file -
    PHP Code:
    <?php 
    $text01 
    $_POST['text01']; 
    $text02 $_POST['text02']; 
    echo 
    "&var1=".$text01."&";
    echo 
    "&var2=".$text02."&";
    is the returned output (in Flash) correct ?

  15. #15
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    The return output is just an XML file. What am I looking for with the echo?

  16. #16
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    sv.onLoad = function(){
    trace("var1="+this.var1); // are these two
    trace("var2="+this.var2); // variables correct ?
    };

    if so, they are correctly being sent to the php file.
    are you certain that you are not viewing a cached version of your xml file ?

  17. #17
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Yes - Positive - infact I'll remove the PHP from the file entirely. When i hit the send button, it does create a new XML file, but the values are not coming through. Here's a link to download:

    http://www.intromotion.com/write_xml/4moddog.zip

    I'm figuring this may be the only way to truely understand what i'm looking at.
    Again - thank you for your help! I've been going crazy to make this work.

  18. #18
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    "unexpected file format" error when opening your version 9 fla file in Flash 8

  19. #19
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Quote Originally Posted by a_modified_dog
    "unexpected file format" error when opening your version 9 fla file in Flash 8
    Ok - try this one:
    http://www.intromotion.com/write_xml/4moddog2.zip

    Are you in need of Flash CS3? I'd be happy to get you an upgrade.

  20. #20
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    http://www.jackleaman.co.uk/modified2.zip

    i hope that this file is close to where you are heading

    upload the php and xml files to your server

    change the Flash file to point to your domain - path = "http: etc"

    test the movie, then go to the winner.xml file in your browser


    your original code was failing for a few reasons, the main one was -

    you had used the Library name for the movieclips in your script
    you must always give the clip an instance name and use that name in your script.
    I gave instance names to the two targets - target01 and target02
    Last edited by a_modified_dog; 11-15-2008 at 03:15 PM.

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