This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-22 17:19:55

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Flash help please!

Whenever I try and run my program, I get this error in the "Output" panel:

Code:

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:

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)


Lurking more than posting, but still here.

Offline

 

#2 2011-10-22 17:23:22

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Flash help please!

Sorry I can't help, but this belongs in AT.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#3 2011-10-22 17:23:33

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Flash help please!

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

 

#4 2011-10-22 17:29:26

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: Flash help please!

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.


Lurking more than posting, but still here.

Offline

 

#5 2011-10-22 18:25:49

puppetadventurer
Scratcher
Registered: 2011-02-20
Posts: 1000+

Re: Flash help please!

WindowsExplorer wrote:

Sorry I can't help, but this belongs in AT.

Advance topics is for advanced scratch related stuff


3

Offline

 

#6 2011-10-22 18:27:20

777w
Scratcher
Registered: 2009-02-10
Posts: 1000+

Re: Flash help please!

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

 

#7 2011-10-22 18:30:22

meowmeow55
Scratcher
Registered: 2008-12-24
Posts: 1000+

Re: Flash help please!

Most coding-type stuff, even if it isn't Scratch-related, generally goes in AT now for some reason.


Yawn.

Offline

 

#8 2011-10-23 12:33:53

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: Flash help please!

GameHutSoftware wrote:

Please, only post if you can actually help.

Guys...


Lurking more than posting, but still here.

Offline

 

#9 2011-10-23 13:05:03

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Flash help please!

They are helping. They're helping you decide where to put this.

I'm helping. I'm helping you learn that they are helping.

Offline

 

#10 2011-10-23 13:16:20

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: Flash help please!

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.


Lurking more than posting, but still here.

Offline

 

#11 2011-10-24 12:53:11

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: Flash help please!

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!


Lurking more than posting, but still here.

Offline

 

#12 2011-10-27 07:54:17

eventexception
Scratcher
Registered: 2011-04-08
Posts: 500+

Re: Flash help please!

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

 

Board footer