• Advertisement
Sign in to follow this  

AS3 Multiple Frame Video Game Problems - Begginer

This topic is 2103 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:


[color=#FF0000]TypeError: Error #1009: Cannot access a property or method of a null object reference.[/color]
[color=#FF0000]at TDQuest/getInventory()[/color]
[color=#FF0000]at TDQuest()[/color]

The full document class code is as follows:


[color=#0000FF]package [/color]
[color=#0000FF]{[/color]
[color=#0000FF]import flash.display.MovieClip;[/color]
[color=#0000FF]import flash.display.SimpleButton;[/color]
[color=#0000FF]import flash.display.*;[/color]
[color=#0000FF]import flash.text.*;[/color]
[color=#0000FF]import flash.ui.*;[/color]
[color=#0000FF]import fl.controls.Button;[/color]
[color=#0000FF]import fl.controls.*;[/color]

[color=#0000FF]public class TDQuest extends MovieClip[/color]
[color=#0000FF]{[/color]
[color=#0000FF]public var invBasic,invCannon,invElemental,invGold,invLumber,invStone,invOre,invGems:uint;[/color]
[color=#0000FF]public var intExp:int;[/color]

[color=#0000FF]public function TDQuest()[/color]
[color=#0000FF]{[/color]
[color=#0000FF]getInventory();[/color]
[color=#0000FF]}[/color]

[color=#0000FF]function UpdateButtons()[/color]
[color=#0000FF]{[/color]
[color=#0000FF]if (currentLabel=="World Map")[/color]
[color=#0000FF]{[/color]
[color=#0000FF]btnNav1.label="Character Sheet";[/color]
[color=#0000FF]btnNav2.label="Inventory";[/color]
[color=#0000FF]btnNav3.label="Shop";[/color]
[color=#0000FF]btnNav4.label="Upgrades";[/color]
[color=#0000FF]btnNav5.label="Crafting";[/color]
[color=#0000FF]btnNav6.label="Main Menu";[/color]
[color=#0000FF]}[/color]
[color=#0000FF]else if (currentLabel=="Character Sheet")[/color]
[color=#0000FF]{[/color]
[color=#0000FF]btnNav1.label="World Map";[/color]
[color=#0000FF]btnNav2.label="Inventory";[/color]
[color=#0000FF]btnNav3.label="Shop";[/color]
[color=#0000FF]btnNav4.label="Upgrades";[/color]
[color=#0000FF]btnNav5.label="Crafting";[/color]
[color=#0000FF]btnNav6.label="Main Menu";[/color]
[color=#0000FF]}[/color]
[color=#0000FF]else if (currentLabel=="Inventory")[/color]
[color=#0000FF]{[/color]
[color=#0000FF]btnNav1.label="World Map";[/color]
[color=#0000FF]btnNav2.label="Character Sheet";[/color]
[color=#0000FF]btnNav3.label="Shop";[/color]
[color=#0000FF]btnNav4.label="Upgrades";[/color]
[color=#0000FF]btnNav5.label="Crafting";[/color]
[color=#0000FF]btnNav6.label="Main Menu";[/color]
[color=#0000FF]}[/color]
[color=#0000FF]else if (currentLabel=="Shop")[/color]
[color=#0000FF]{[/color]
[color=#0000FF]btnNav1.label="World Map";[/color]
[color=#0000FF]btnNav2.label="Character Sheet";[/color]
[color=#0000FF]btnNav3.label="Inventory";[/color]
[color=#0000FF]btnNav4.label="Upgrades";[/color]
[color=#0000FF]btnNav5.label="Crafting";[/color]
[color=#0000FF]btnNav6.label="Main Menu";[/color]
[color=#0000FF]}[/color]
[color=#0000FF]else if (currentLabel=="Upgrades")[/color]
[color=#0000FF]{[/color]
[color=#0000FF]btnNav1.label="World Map";[/color]
[color=#0000FF]btnNav2.label="Character Sheet";[/color]
[color=#0000FF]btnNav3.label="Inventory";[/color]
[color=#0000FF]btnNav4.label="Shop";[/color]
[color=#0000FF]btnNav5.label="Crafting";[/color]
[color=#0000FF]btnNav6.label="Main Menu";[/color]
[color=#0000FF]}[/color]
[color=#0000FF]else if (currentLabel=="Crafting")[/color]
[color=#0000FF]{[/color]
[color=#0000FF]btnNav1.label="World Map";[/color]
[color=#0000FF]btnNav2.label="Character Sheet";[/color]
[color=#0000FF]btnNav3.label="Inventory";[/color]
[color=#0000FF]btnNav4.label="Shop";[/color]
[color=#0000FF]btnNav5.label="Upgrades";[/color]
[color=#0000FF]btnNav6.label="Game Screen";[/color]
[color=#0000FF]}[/color]
[color=#0000FF]}[/color]

[color=#0000FF]public function getInventory()[/color]
[color=#0000FF]{[/color]
[color=#0000FF]gotoAndStop("Inventory");[/color]
[color=#0000FF]invBasic=Number(inventoryBasic.text);[/color]
[color=#0000FF]invCannon=Number(inventoryCannon.text);[/color]
[color=#0000FF]invElemental=Number(inventoryElemental.text);[/color]
[color=#0000FF]invGold=Number(inventoryGold.text);[/color]
[color=#0000FF]invLumber=Number(inventoryLumber.text);[/color]
[color=#0000FF]invStone=Number(inventoryStone.text);[/color]
[color=#0000FF]invOre=Number(inventoryOre.text);[/color]
[color=#0000FF]invGems=Number(inventoryGems.text);[/color]
[color=#0000FF]trace("Basic Towers: " + invBasic);[/color]
[color=#0000FF]trace("Cannon Towers: " + invCannon);[/color]
[color=#0000FF]trace("Elemental Towers: " + invElemental);[/color]
[color=#0000FF]trace("Gold: " + invGold);[/color]
[color=#0000FF]trace("Lumber: " + invLumber);[/color]
[color=#0000FF]trace("Stone: " + invStone);[/color]
[color=#0000FF]trace("Ore: " + invOre);[/color]
[color=#0000FF]trace("Gems: " + invGems);[/color]
[color=#0000FF]}[/color]
[color=#0000FF]}[/color]
[color=#0000FF]}[/color]

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thank you paulstamp, I will try setting up an enterframe function. As for the data, I am trying to pass the information back and forth between the frames and the code. I will let you know how it turns out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement