A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: can't get variable to display right

Hybrid View

  1. #1
    Member
    Join Date
    Jan 2006
    Posts
    45

    can't get variable to display right

    This is probably a pretty simple problem, but i'm stuck. I need to get the profile_id variable in the below code...

    Code:
    MyVars = new LoadVars ();
    MyVars.onLoad = function () {
    	//save profile_id to pass to uploader
    	_root.profile_id= MyVars.profile_id;
    	//save songs for this user
       songsArray = serial.unserialize(this.initSongsPHP);
    	len = songsArray.length;
      for(var i=0; i<len; i++){
       songDisplay.text += songsArray[i] + "\n";
      }
      
    
    };
    MyVars.load ('php_scripts/flash_interact.php?action=initialize');
    To display later in on in the actionscript here, added to the scriptLocation string here:

    Code:
    var scriptLocation:String = 'php_scripts/flash_interact.php?action=add&profile_id' + _root.profile_id;
    the profile_id variable doesn't seem to make it to the URL variable here. Through debugging I know that the profile_id variable gets set in the first chunk of code.

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    This line is wrong:
    _root.profile_id= MyVars.profile_id;

    Since that line is inside the onLoad function, your scope is relative to MyVars. There is no MyVars inside of MyVars. You could have verified this by immediatly following that line with trace(_root.profile_id); You saw the variable in debugging but it likely had undefined as it's value.

    Again, since you are trying to retrieve values from inside MyVars, you can just say this. Elsewhere in the code you would have to refer to MyVars directly.

    replace:
    _root.profile_id= MyVars.profile_id;
    with:
    _root.profile_id= this.profile_id;

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