Results 1 to 3 of 3

Thread: Action Script 2.0 Help needed!

  1. #1
    Join Date
    Oct 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Action Script 2.0 Help needed!

    Hi. Currently, i'm facing some action scripts problem. I need to create a flash which get the external/dynamic data from .txt, after getting data value and gotoAndPlay another scene. Below script seemed not workable.. Coz can't get the right variable and keep playing the wrong scene. Any flash expert willing to help me?

    My text file content is :
    point= 8000

    Code is :
    var myData= new LoadVars();
    myData.load("details.txt");
    totalpoint.text = this.point;
    myData.onLoad = function(totalpoint:Number) {

    if((totalpoint > 8000) && (totalpoint < 10000)) {
    gotoAndPlay("Scene 5", 1);
    } else if ((totalpoint > 7999) && (totalpoint < 6000)) {
    gotoAndPlay("Scene 4", 1);
    } else if ((totalpoint > 5999) && (totalpoint < 3000)) {
    gotoAndPlay("Scene 3", 1);
    } else {
    gotoAndPlay("Scene 2", 1);

    }
    }

    Thank you very much.

  2. #2
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi there.. a couple of issues with your code. firstly your mydata.onload function. The totalpoint parameter is returning a boolean value indicating successful/failure for the load event not a number. So I presume you will always default to gotoandplay("scene 2", 1);
    Your if statements appear to be mutually exclusive i.e.
    Assuming a point value of 8000
    if(totalpoint>8000 && totalpoint<10000) will fail as 8000 is not greater than 8000.
    if(totalpoint>7999 && totalpoint <6000) will fail as 8000 cannot be greater than 7999 and less than 6000. The same applies to the other if statements, the if conditionals will always return false
    changing your onload function to the something similar should help resolve the issues

    myData.onLoad = function(success:Boolean)
    {
    var ipointval:Number;
    //onload function returns true for success
    if (success) {
    //set up the point value from the details.txt file
    ipointVal = this.point;

    if((ipointVal >= 8000) && (ipointVal <= 10000))

    {
    trace("scene 5 selected");
    gotoAndPlay("Scene 5", 1);
    }
    else if ((ipointVal >= 6000) && (ipointVal < 8000))
    {
    trace("scene 4 selected");
    gotoAndPlay("Scene 4", 1);
    }
    else if ((ipointVal >= 3000) && (ipointVal < 6000))
    {
    trace("scene 3 selected");
    gotoAndPlay("Scene 3", 1);
    }
    else
    {
    trace("scene 2 selected");
    gotoAndPlay("Scene 2", 1);
    }

    //if function returns false for boolean success
    }
    else
    {
    trace("Error loading/parsing LoadVars.");
    }

    }


    Hope this helps!!

  3. #3
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Another point to look at, which was corrected in the above post but not mentioned, you need the old "double variables" inside your If statements.

    so if ((totalpoint > 8000) && (totalpoint < 10000)) {

    becomes if((totalpoint >= 8000) && (totalpoint <= 10000)) {

    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •