Hey All,
I am trying to have my Dynamic Text values communicate across several frames and with the document class. I get a consistent error that states my dynamic text fields contain null values, when they contain numeric values at the time of running the code.
The error is as follows:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at TDQuest/getInventory()
at TDQuest()
The full document class code is as follows:
package
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.*;
import flash.text.*;
import flash.ui.*;
import fl.controls.Button;
import fl.controls.*;
public class TDQuest extends MovieClip
{
public var invBasic,invCannon,invElemental,invGold,invLumber,invStone,invOre,invGems:uint;
public var intExp:int;
public function TDQuest()
{
getInventory();
}
function UpdateButtons()
{
if (currentLabel=="World Map")
{
btnNav1.label="Character Sheet";
btnNav2.label="Inventory";
btnNav3.label="Shop";
btnNav4.label="Upgrades";
btnNav5.label="Crafting";
btnNav6.label="Main Menu";
}
else if (currentLabel=="Character Sheet")
{
btnNav1.label="World Map";
btnNav2.label="Inventory";
btnNav3.label="Shop";
btnNav4.label="Upgrades";
btnNav5.label="Crafting";
btnNav6.label="Main Menu";
}
else if (currentLabel=="Inventory")
{
btnNav1.label="World Map";
btnNav2.label="Character Sheet";
btnNav3.label="Shop";
btnNav4.label="Upgrades";
btnNav5.label="Crafting";
btnNav6.label="Main Menu";
}
else if (currentLabel=="Shop")
{
btnNav1.label="World Map";
btnNav2.label="Character Sheet";
btnNav3.label="Inventory";
btnNav4.label="Upgrades";
btnNav5.label="Crafting";
btnNav6.label="Main Menu";
}
else if (currentLabel=="Upgrades")
{
btnNav1.label="World Map";
btnNav2.label="Character Sheet";
btnNav3.label="Inventory";
btnNav4.label="Shop";
btnNav5.label="Crafting";
btnNav6.label="Main Menu";
}
else if (currentLabel=="Crafting")
{
btnNav1.label="World Map";
btnNav2.label="Character Sheet";
btnNav3.label="Inventory";
btnNav4.label="Shop";
btnNav5.label="Upgrades";
btnNav6.label="Game Screen";
}
}
public function getInventory()
{
gotoAndStop("Inventory");
invBasic=Number(inventoryBasic.text);
invCannon=Number(inventoryCannon.text);
invElemental=Number(inventoryElemental.text);
invGold=Number(inventoryGold.text);
invLumber=Number(inventoryLumber.text);
invStone=Number(inventoryStone.text);
invOre=Number(inventoryOre.text);
invGems=Number(inventoryGems.text);
trace("Basic Towers: " + invBasic);
trace("Cannon Towers: " + invCannon);
trace("Elemental Towers: " + invElemental);
trace("Gold: " + invGold);
trace("Lumber: " + invLumber);
trace("Stone: " + invStone);
trace("Ore: " + invOre);
trace("Gems: " + invGems);
}
}
}
I have tried moving the code into separate functions, new classes and other document classes. I cannot seem to get the data to transfer to the document class or other frames. I have tried having the document class create and place the text fields with the same result. I am starting to think that there is a configuration setting that I am missing.
Any advice or suggestions would be appreciated.
AS3 Multiple Frame Video Game Problems - Begginer
Started by Phlaw, Apr 14 2012 12:42 AM
4 replies to this topic
Sponsor:
#2 Members - Reputation: 100
Posted 15 April 2012 - 08:36 AM
the likely issue is that when calling the gotoAndStop method the contents of the frame don't load immediately . There are two solutions that spring to mind. Either add an enter frame event and check the current frame name until it equals "Inventory" then chek the contents of your text fields or add a frame script using the addFrameScript method which you can find out how use with a quick google search. Hope that helps.
#3 Members - Reputation: 100
Posted 15 April 2012 - 08:47 AM
As a side note it's note a great idea to obtain data from your text fields unless they are input fields and the data is user generated. The better approach is to store the numbers for your gold, lumber and stone in code updating your text fields to display this information as it changes. This helps seperate your visual elements further from your code elements.






