SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2007
    Location
    Perth
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Flash AS3 - Passing between variables

    Hi There,

    I'm trying to retrieve a score from a database, hold it in a variable and then use it within other action script functions.

    I have managed to retrieve the score froom the database just fine, however I am having a problem passing the result from the user_score variable to the score variable so that I can reuse the value throughout the rest of the action script.

    Can anyone shed some light on what I'm doing wrong?

    Please see the snippet below:

    Code:
    //Get The Score from the database
    var variables:URLVariables = new URLVariables();
    var request:URLRequest = new URLRequest();
    request.method = URLRequestMethod.POST;
    var loader:URLLoader = new URLLoader();
    request.url = "http://www.operationclimatechange.com.au/layer/ws/xFlashScore.php";
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, completeHandler);
    loader.load(request);
    
    
    			
    //Function to Get  Score of the logged in user and store it in a variable called "score"
    function completeHandler(event:Event):void{
    var user_score=event.target.data.score;
    user_score=score;
    trace(user_score);
    
    
    
    // Score Scale //
    //score user earns in missions
    var score=0;
    var total_balloons=1400;//total balloons available 1200
    var balloons=0;// balloons earnt or lost in the game for each object
    var user_balloons=score+balloons;//total ballons won or lost during game
    var getPercentage=user_balloons/total_balloons;
    this.balloonBar.height=getPercentage*100;
    trace(score);
    }
    Flamingcow Design - Perth, WA

  2. #2
    SitePoint Wizard jim_morrison3's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    2,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var user_score=event.target.data.score;
    user_score=score;
    trace(user_score);
    In your complehandler() method you are setting the value of user_score=score after initializing it with the score you are getting from the database. Later in your code you have declared and initialized score with a value 0.
    Good Luck!
    There are things known and Things unknown
    And in between are the Doors.
    I love hand Coding.

  3. #3
    SitePoint Member
    Join Date
    Apr 2007
    Location
    Perth
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jim_morrison3 View Post
    In your complehandler() method you are setting the value of user_score=score after initializing it with the score you are getting from the database. Later in your code you have declared and initialized score with a value 0.
    Cheers! I have effectively written over the user_score with 0. I managed to create another function and pass the user_score value to the score variable. I think it's working for the time being, however I may be back in a couple of hours
    Flamingcow Design - Perth, WA


Tags for this Thread

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
  •