A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: load vars from a php file

  1. #1
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24

    load vars from a php file

    Hi all

    I'm wanting to load a variable from a php file and I've found heaps of code on this but I can't seem to work it out to do what I need.

    I think it's the "LoadVars();" actionscript I need to understand.

    hear is the variable in the php file:

    PHP Code:
    <?php 
    $head 
    $_GET['head']; 
    ?>
    The head is set from an html link.

    and it's hear where I need to get the $head variable into flash and then do the following:

    if $head = 1 then gotoAndStop("lable_1");
    if $head = 2 then gotoAndStop("lable_2");
    if $head = 3 then gotoAndStop("lable_3");

    And so on and so on......

    Any ideas

    Cheers
    Chris

  2. #2
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    PHP

    echo "&head=" . $_GET['head'];


    myLoader = new LoadVars();
    myLoader.onLoad = function()
    {
    trace(head)
    }

  3. #3
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    Oups


    PHP

    echo "&head=" . $_GET['head'];

    Flash

    myLoader = new LoadVars();
    myLoader.onLoad = function()
    {
    trace(this.head)
    }

  4. #4
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24
    This doesn't seem to work....any ideas.

    code:

    myLoader.load("site.php");
    myLoader = new LoadVars();
    myLoader.onLoad = function()
    {
    trace(this.head)
    }
    whichlable = this.head

    if (whichlable = "1") {
    gotoAndStop("lable_1");
    }
    if (whichlable = "2") {
    gotoAndStop("lable_2");
    }




    Cheers
    Chris
    Last edited by cybercampbell; 08-20-2004 at 11:40 AM.

  5. #5
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    Use that

    myLoader = new LoadVars();
    myLoader.onLoad = function()
    {
    this._parent.gotoAndStop("lable_" + this.head);


    }
    myCaller.sendAndLoad ("site.php", myCaller, "POST");

  6. #6
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24
    Thanks mate

    I have decided to rename my lables.

    What was the code that you previously posted were I could specify the lable names.

    Thanks Chris

  7. #7
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    myLoader = new LoadVars();
    myLoader.onLoad = function()
    {
    if(this.head == "1")
    {
    this._parent.gotoAndStop("label_1");
    }
    else(this.head == "2")
    {
    this._parent.gotoAndStop("label_2");
    }
    }
    myCaller.sendAndLoad ("site.php", myCaller, "POST");

  8. #8
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24
    Ok...I've done that.

    But it 's not working so clearly i'm doing something wrong.

    If the label "lable_1" is in a movie clip called "nav", should I put extra code in to tell it to go there?

    Where should I place this code....in the first frame or in the movie clip where the labels are?

    Thanks for your help

    Chris

  9. #9
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    myLoader = new LoadVars();
    myLoader.onLoad = function()
    {
    if(this.head == "1")
    {
    this._parent.nav.gotoAndStop("label_1");
    }
    else(this.head == "2")
    {
    this._parent.nav.gotoAndStop("label_2");
    }
    }
    myCaller.sendAndLoad ("site.php", myCaller, "POST");

    //////

    myLoader is an object that you create into the movie that hold the timeline where you put the code. In your case i believe its on the _root of the movie (main timeline). The 'nav' movie is also, i believe, into your main timeline.

    Since the 'onLoad' event is in myLoader you use this._parent to refer to the main timeline and then you put .nav to refer to your 'nav' movie.

    Make sure that the movie as the instance name 'nav'. The name in the library is only for developement reference but as no instance on actionscript.

  10. #10
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    But it may not work also because i made a mystake ..... Sory!

    myLoader = new LoadVars();
    myLoader.onLoad = function()
    {
    if(this.head == "1")
    {
    this._parent.nav.gotoAndStop("label_1");
    }
    else(this.head == "2")
    {
    this._parent.nav.gotoAndStop("label_2");
    }
    }
    myLoader.sendAndLoad ("site.php", myLoader, "POST");

  11. #11
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    there is what should work if your php return 1 or 2 as a string

  12. #12
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24
    Thanks mate...I'll try it now and I'll let you know how I go.

    Cheers
    Chris

  13. #13
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24
    maybe I'm not setting the variable corectly.
    could you please check this for me.

    I changed this line:
    myLoader.sendAndLoad ("test.php", myLoader, "POST");

    for the test.php

    also I changed a stop(): to a stop(); in the nav movie clip.

    you'll have to take of the .txt at the end of the file I uploaded

    Thanks for your help.
    Chris
    Attached Files Attached Files

  14. #14
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    the page you send me should be call index.html and you should have another file name test.php wich contain only the php

  15. #15
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24
    is there any way of flash grabing the variable from the page it's embeded in?

    thanks again for all you help

    Chris

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