A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS2 - Flashvars Scope

  1. #1
    Member
    Join Date
    Jun 2008
    Posts
    82

    AS2 - Flashvars Scope

    I'm trying to figure out a massive scope issue with AS2 Flashvars. So far, I've gotten all of my scripts working within "on success" load. However, the program I'm writing calls for the occasional reload of several variables.

    What I'd like to do is access loaded variables outside the on(success) method in FlashVars, but so far the scope has evaded me. this. works, but licenseLoad.
    doesn't if I try to remove licenseLoad.onLoad = function(success).

    Code:
    // Load Variables //
    
    licenseLoad = new LoadVars();
    
    licenseLoad.onLoad = function(success) {
    // Initial Setup //
    // Names //
    player.text = this.player;
    enemy.text = this.enemy;
    
    // HP //
    // Setup Player and Enemy Hitpoints //
    playerHP = 500;
    enemyHP = 500;
    
    // Report Player HP //
    hp.text = playerHP;
    eHP.text = enemyHP;
    
    // Turn Phase // 
    phase = 1;
    // 1 - "Auto Draw Card" //
    // 2 - Active Phase - Flip Drawn Card //
    // 3 - Interaction Phase - Choose Action //
    // Attack / Defend / Boost //
    // 4 - End Phase //
    
    // Turn Control //
    turn = 1;
    
    switch (phase) {
    	case 1:
    	turn.text = "Draw Card"; 
    	drawButton._alpha=100; 
    	attack._alpha=20; 
    	defend._alpha=20; 
    	boost._alpha=20;
    	attack.enabled = false;
    	defend.enabled = false;
    	boost.enabled = false;
    	drawButton.enabled = true; 
    	break;
    	case 2:
    	turn.text = "Active Phase";  
    	drawButton._alpha=20; 
    	attack._alpha=100; 
    	defend._alpha=100; 
    	boost._alpha=100;
    	attack.enabled = true;
    	defend.enabled = true;
    	boost.enabled = true;
    	drawButton.enabled = false; 
    	break;
    	case 3:
    	turn.text = "Battle Phase"; 
    	drawButton._alpha=20;
    	attack._alpha=20; 
    	defend._alpha=20; 
    	boost._alpha=20;
    	attack.enabled = false;
    	defend.enabled = false;
    	boost.enabled = false;
    	drawButton.enabled = false; 
    	break;
    	case 4:
    	turn.text = "End Phase"; 
    	drawButton._alpha=20;
    	attack._alpha=20; 
    	defend._alpha=20; 
    	boost._alpha=20;
    	attack.enabled = false;
    	defend.enabled = false;
    	boost.enabled = false;
    	drawButton.enabled = false; 
    	break;
    }
    
    // Player License Setup //
    
    // Load License //
    licenseName = this.licenseName;
    license.licenseHolder.contentPath = "/site/minithumbs/" + this.licensePicture;
    // License Variable Setup //
    knowledge = this.knowledge;
    logic = this.logic;
    focus = this.focus;
    speed = this.speed;
    
    // Set Support Card Status //
    playerSupport = "NotReady";
    
    // Choose Support Type //
    supportType = this.type;
    
    if (supportType == "License") {
    Ksupport = this.supportKnow;
    Lsupport = this.supportLogic;
    Fsupport = this.supportFocus;
    Ssupport = this.supportSpeed;
    } else {
    effectOneTarget = this.targetOne;
    effectTwoTarget = this.targetTwo;
    effectOne = this.sEffectOne;
    effectType = this.sEffectOneType;
    effectTwo = this.sEffectTwo;
    effectTypeTwo = this.sEffectTwoType;
    }
    
    // Load Enemy License //
    
    // Load License //
    enemyPic = this.ElicensePicture;
    enemyLicense.enemyLoader.contentPath = "/site/minithumbs/" + enemyPic;
    // License Variable Setup //
    eKnowledge = this.knowledge;
    eLogic = this.logic;
    eFocus = this.focus;
    eSpeed = this.speed;
    
    // Rollover Effects //
    
    license.onRollOver = function() {
    	playerReporter.text = "Name:" + licenseName + ", " +"Knowledge:" + knowledge + ", " +"Logic:" + logic  + ", " + "Speed:" + speed  + " ," + "Focus:" + focus;
    }
    
    license.onRollOut = function() {
    	playerReporter.text = "";
    }
    
    supportCard.onRollOver = function () {
    	if (playerSupport == "NotReady") {
    		playerReporter.text = "This card is set!";	
    	} else {
    		if (supportType == "License") {
    				playerReporter.text = "Knowledge:" + Ksupport + " Logic:" + Lsupport + " Speed:" + Ssupport + " Focus:" + Fsupport;
    		} else {
    				playerReporter.text = " Ability One:" + effectOne + " Ability Two:" + effectTwo+ " Targets:" + effectOneTarget + " Second Target:" + effectTwoTarget;
    		}
    	}
    }
    supportCard.onRollOut = function() {
    	playerReporter.text = "";
    }
    }
    
    // Load All Variables // 
    licenseLoad.load("/***/flashInfo.php");

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    You want to use variables loaded during the license load outside of the function? Did you attempt to pass the information to another function, or update a global variables, so it won't matter when you run the load, the content will be available to everyone.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Member
    Join Date
    Jun 2008
    Posts
    82
    I tried to set up variables for the functions outside the function, but as the manual explains they were just "cloaked" by the functions inside the variables.
    I also attempted to use _root. to reach those variables but got nowhere, and the same with _parent. Not really sure what else to do.

  4. #4
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Okay, it doesn't appear that any of your storage variables are global. Because you are declaring them within a function, they become local. You can instantiate a variable within a function, but must declare it outside the function for it to be global.

    I also noticed that you have a ton of variables, I suggest you save the information into a global object variable. For example I would call it licenseData. This way you can use the dot notation to access the information in a familiar manner. If you do that in the beginning, then you won't need to continually pass and store different parts of the data, unless it changes.

    PHP Code:
    // Load Variables //
    var licenseData:Object = new Object();

    licenseLoad = new LoadVars();

    licenseLoad.onLoad = function(success) {
        
    licenseData licenseLoad;        //Will store everything that returns from the load
        
        // Initial Setup //
        // Names //
        
    player.text this.player;
        
    enemy.text this.enemy
    This is only an example, since I can 't confirm the return, but something similar will work for you.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  5. #5
    Member
    Join Date
    Jun 2008
    Posts
    82
    So I should try setting up licenseData as an outside global, like doing this?

    _global.licenseData;

    (inside function) {

    licenseLoad = licenseData;

    }

    Oops, didn't see the var setup. Trying this now.
    Last edited by Teonnyn; 03-22-2010 at 10:19 PM.

  6. #6
    Member
    Join Date
    Jun 2008
    Posts
    82
    No such luck. Variables still refuse to be read outside the onLoad method.

  7. #7
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Well then, I guess we need to take a step back and get on the same track. What is the content of the file you are trying to load? I noticed you are trying to pull from a PHP file, has that been successful?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

Tags for this Thread

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