Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


AS3 Multiple Frame Video Game Problems - Begginer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Phlaw   Members   -  Reputation: 101

Like
0Likes
Like

Posted 14 April 2012 - 12:42 AM

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.

Sponsor:

#2 paulstamp   Members   -  Reputation: 100

Like
0Likes
Like

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 paulstamp   Members   -  Reputation: 100

Like
0Likes
Like

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.

#4 Phlaw   Members   -  Reputation: 101

Like
0Likes
Like

Posted 16 April 2012 - 03:30 PM

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.

#5 Phlaw   Members   -  Reputation: 101

Like
0Likes
Like

Posted 17 April 2012 - 11:41 AM

Thanks alot paulstamp! It worked, my fields now update...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS