Whenever I try and run my program, I get this error in the "Output" panel:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Calculate/init()
at Calculate()What does it mean? Here's my code:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class Calculate extends MovieClip
{
var inputCurrency:uint;
var outputCurrency:uint;
var firstCurrency:String;
var secondCurrency:String;
public function Calculate()
{
17 init();
}
function init():void
{
firstCurrency = "usdollar";
secondCurrency = "usdollar";
inputCurrency = 0.00;
outputCurrency = 0.00;
25 input.restrict = "0-9.";
stage.focus = input;
currencyOne.gotoAndStop(1);
currencyTwo.gotoAndStop(1);
currencyOne.addEventListener(MouseEvent.CLICK,onFirstCurrencyClick);
currencyTwo.addEventListener(MouseEvent.CLICK,onSecondCurrencyClick);
calculateButton.addEventListener(MouseEvent.CLICK,onCalculateButtonClick);
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPress);
}
function onFirstCurrencyClick(event:MouseEvent):void
{
if (firstCurrency == "usdollar")
{
currencyOne.gotoAndStop(2);
firstCurrency = "euro";
}
else if (firstCurrency == "euro")
{
currencyOne.gotoAndStop(3);
firstCurrency = "japaneseyen";
}
if (firstCurrency == "japaneseyen")
{
currencyOne.gotoAndStop(4);
firstCurrency = "britishpound";
}
else if (firstCurrency == "britishpound")
{
currencyOne.gotoAndStop(5);
firstCurrency = "swissfranc";
}
if (firstCurrency == "swissfranc")
{
currencyOne.gotoAndStop(6);
firstCurrency = "australiandollar";
}
else if (firstCurrency == "australiandollar")
{
currencyOne.gotoAndStop(7);
firstCurrency = "canadiandollar";
}
if (firstCurrency == "canadiandollar")
{
currencyOne.gotoAndStop(8);
firstCurrency = "swedishkrona";
}
else if (firstCurrency == "swedishkrona")
{
currencyOne.gotoAndStop(9);
firstCurrency = "hongkongdollar";
}
if (firstCurrency == "hongkongdollar")
{
currencyOne.gotoAndStop(10);
firstCurrency = "norwegiankrone";
}
else if (firstCurrency == "norwegiankrone")
{
currencyOne.gotoAndStop(1);
firstCurrency = "usdollar";
}
}
function onSecondCurrencyClick(event:MouseEvent):void
{
if (secondCurrency == "usdollar")
{
currencyTwo.gotoAndStop(2);
secondCurrency = "euro";
}
else if (secondCurrency == "euro")
{
currencyTwo.gotoAndStop(3);
secondCurrency = "japaneseyen";
}
if (secondCurrency == "japaneseyen")
{
currencyTwo.gotoAndStop(4);
secondCurrency = "britishpound";
}
else if (secondCurrency == "britishpound")
{
currencyTwo.gotoAndStop(5);
secondCurrency = "swissfranc";
}
if (secondCurrency == "swissfranc")
{
currencyTwo.gotoAndStop(6);
secondCurrency = "australiandollar";
}
else if (secondCurrency == "australiandollar")
{
currencyTwo.gotoAndStop(7);
secondCurrency = "canadiandollar";
}
if (secondCurrency == "canadiandollar")
{
currencyTwo.gotoAndStop(8);
secondCurrency = "swedishkrona";
}
else if (secondCurrency == "swedishkrona")
{
currencyTwo.gotoAndStop(9);
secondCurrency = "hongkongdollar";
}
if (secondCurrency == "hongkongdollar")
{
currencyTwo.gotoAndStop(10);
secondCurrency = "norwegiankrone";
}
else if (secondCurrency == "norwegiankrone")
{
currencyTwo.gotoAndStop(1);
secondCurrency = "usdollar";
}
}
function onCalculateButtonClick(event:MouseEvent):void
{
doYourStuff();
}
function onKeyPress(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.ENTER)
{
doYourStuff();
}
}
function doYourStuff():void
{
inputCurrency = uint(input.text);
if (firstCurrency == "usdollar")
{
if (secondCurrency == "usdollar")
{
outputCurrency = inputCurrency * 1;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " US Dollars";
}
else if (secondCurrency == "euro")
{
outputCurrency = inputCurrency * 1.37;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " Euros";
}
if (secondCurrency == "japaneseyen")
{
outputCurrency = inputCurrency * 0.01;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " Japanese Yen";
}
else if (secondCurrency == "britishpound")
{
outputCurrency = inputCurrency * 1.57;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " British Pounds";
}
if (secondCurrency == "swissfranc")
{
outputCurrency = inputCurrency * 1.11;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " Swiss Francs";
}
else if (secondCurrency == "australiandollar")
{
outputCurrency = inputCurrency * 1.02;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " Australian Dollars";
}
if (secondCurrency == "canadiandollar")
{
outputCurrency = inputCurrency * 0.98;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " Canadian Dollars";
}
else if (secondCurrency == "swedishkrona")
{
outputCurrency = inputCurrency * 0.15;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " Swedish Krona";
}
if (secondCurrency == "hongkongdollar")
{
outputCurrency = inputCurrency * 0.12;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " Hong Kong Dollars";
}
else if (secondCurrency == "norwegiankrone")
{
outputCurrency = inputCurrency * 0.17;
output.text = inputCurrency + " US Dollars = " + outputCurrency + " Norwegian Krones";
}
}
if (firstCurrency == "euro")
{
if (secondCurrency == "usdollar")
{
outputCurrency = inputCurrency * 0.72;
output.text = inputCurrency + " Euros = " + outputCurrency + " US Dollars";
}
else if (secondCurrency == "euro")
{
outputCurrency = inputCurrency * 1;
output.text = inputCurrency + " Euros = " + outputCurrency + " Euros";
}
if (secondCurrency == "japaneseyen")
{
outputCurrency = inputCurrency * 0.01;
output.text = inputCurrency + " Euros = " + outputCurrency + " Japanese Yen";
}
else if (secondCurrency == "britishpound")
{
outputCurrency = inputCurrency * 1.14;
output.text = inputCurrency + " Euros = " + outputCurrency + " British Pounds";
}
if (secondCurrency == "swissfranc")
{
outputCurrency = inputCurrency * 0.80;
output.text = inputCurrency + " Euros = " + outputCurrency + " Swiss Francs";
}
else if (secondCurrency == "australiandollar")
{
outputCurrency = inputCurrency * 0.74;
output.text = inputCurrency + " Euros = " + outputCurrency + " Australian Dollars";
}
if (secondCurrency == "canadiandollar")
{
outputCurrency = inputCurrency * 0.71;
output.text = inputCurrency + " Euros = " + outputCurrency + " Canadian Dollars";
}
else if (secondCurrency == "swedishkrona")
{
outputCurrency = inputCurrency * 0.10;
output.text = inputCurrency + " Euros = " + outputCurrency + " Swedish Krona";
}
if (secondCurrency == "hongkongdollar")
{
outputCurrency = inputCurrency * 0.09;
output.text = inputCurrency + " Euros = " + outputCurrency + " Hong Kong Dollars";
}
else if (secondCurrency == "norwegiankrone")
{
outputCurrency = inputCurrency * 0.12;
output.text = inputCurrency + " Euros = " + outputCurrency + " Norwegian Krones";
}
}
}
}
}Please, only post if you can actually help.
Last edited by GameHutSoftware (2011-10-23 12:48:52)
Offline
Well, I'm not all that great with AS and have never used classes (my lessons have only covered the external *.as-type classes), but do you need the 'function name(event:Event)' thing?
Offline
maxskywalker wrote:
Well, I'm not all that great with AS and have never used classes (my lessons have only covered the external *.as-type classes), but do you need the 'function name(event:Event)' thing?
No, that just got me a bunch of compiler errors.
Offline
WindowsExplorer wrote:
Sorry I can't help, but this belongs in AT.
Advance topics is for advanced scratch related stuff
Offline
puppetadventurer wrote:
WindowsExplorer wrote:
Sorry I can't help, but this belongs in AT.
Advance topics is for advanced scratch related stuff
not always
once i looked there
LOOKED
THERE
not posted
im not smart enought to post there
anyway,
once i looked there
and saw some other stuff that was all like
super duper scratch unrelated
Offline
Most coding-type stuff, even if it isn't Scratch-related, generally goes in AT now for some reason.
Offline
GameHutSoftware wrote:
Please, only post if you can actually help.
Guys...
Offline
Okay, I've pinpointed the problems to lines 17 and 25. Line 17 creates the "init" function, and line 25 keeps you from entering letters into the "input" box.
Offline
Yes! I got it! The "init" function can't be void because it has to return values! Now it's not returning values for some reason, but I got it!
Offline
http://www.ultrashock.com/forum/viewthread/91757
Found via google ´Error #1009: Cannot access a property or method´
I was just curious, never did anything with Flash.
Do you have some Flash stuff online to see? Link to?
What Flash tools or compilers do you use?
Offline