ActionScript 3 Error 1009. Basic coding really - actionscript-3

So I'm writing a really basic app for an app dev class but I'm a designer than a developer so bear with me on this.
It involves using Caurina tweeners just moving stuff around.
import caurina.transitions.*;
import flash.events.MouseEvent;
stop();trace(fab_mc);
//Scene 2 Nav Scripts
//fab 1&2
fab_mc.fab2_btn.addEventListener(MouseEvent.CLICK, fab2);
function fab2(event:MouseEvent):void
{
Tweener.addTween(fab_mc,{x:-637.4,time:1,transition:"easeInOutQuart"});
}
fab_mc.fab1_btn.addEventListener(MouseEvent.CLICK, fab1);
function fab1(event:MouseEvent):void
{
Tweener.addTween(fab_mc,{x:-136.70,time:1,transition:"easeInOutQuart"});
}
It blows up (according to the debugger ) at line 7 due to "fab_mc" being apparently null. Frankly, I had no idea what a null is about until just this morning - I wrote the code yesterday, it worked fine.
But when I added some more content and coded it, it started complaining. The code for is essentially a lot of tweeners. Sorry if I'm not providing a lot of info, but it's all I have really.
Error code:
null
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Arafabricator_fla::MainTimeline/frame2()[Arafabricator_fla.MainTimeline::frame2:7]
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at Arafabricator_fla::fab_mc_10()
at flash.display::MovieClip/nextScene()
at Arafabricator_fla::MainTimeline/menu07()[Arafabricator_fla.MainTimeline::frame1:64]

If fab_mc is null it means it does not exist on the frame that you have that code. Just make sure you put that code on a frame where the fab_mc symbol also exists. You can't, for example, put that code on frame 1 but the symbol first exists on a keyframe on frame 5. In that case put the code on a keyframe on frame 5 as well.

Related

TypeError 1009, began appearing randomly after adding new button code

SOLVED: It was a two stop functions. Two. Stop. Functions. AS3 can be so annoying sometimes.
I am making a space invaders style game for a school assignment. I was adding in a button to go between frames and I deleted an unnecessary layer that contained a single sprite in my game, which I added back onto the main code layer. Then after attempting to restart my game to check the button, I began receiving a TypeError Code 1009. It is stating that there is an error with MainTimeline/moveBullet() and, MainTimeline/eFrame(). These sections of the code were not altered whatsoever during the creation of the button or movement of the sprite, however, as the bullet is linked to the moving sprite I think the error may be there. I'll put the code below, if anyone knows how to fix this specifically or has a general idea of how to do so please let me know. This is due in a few hours and would greatly appreciate a quick fix. Thanks.
Re-named sprites, re-typed code sections returning errors again. Most fixes appear to be in instance names, corrected them and no fix.
this.addEventListener(Event.ENTER_FRAME, eFrame)
function eFrame(e: Event) {
controls();
restrain();
moveBullet();
enemyHit();
barrierHit();
function moveBullet() {
if (bull.visible == true) {
bull.y -= bulletspeed;
if (bull.y < 0) {
bull.visible = false;
}
}
}
The game had been running fine until this point. The character would move along bottom and shoot up at "bad guys". Bullets were removing bad guys. Now I get the usual super fast run through frames repeatedly. NO Compiler Errors, just output, being
TypeError: Error #1009
"I deleted an unnecessary layer that contained a single sprite in my game, which I added back onto the main code layer. Then after attempting to restart my game to check the button, I began receiving a TypeError Code 1009."
Possible solutions:
(1)
Did you also give the Sprite an instance name? I suspect the name bull is what's expected.
(2)
Eliminate that the problem is in moveBullet(). Disable the call and if the error still exists, then the problem must be between variables bull and bulletspeed.
Comment the call movebullet() in function eFrame:
function eFrame(e: Event)
{
//moveBullet();
....

Actionscript 3 problems with "Call to a possibly undefined method"

Thanks partly to info from people here, I'm getting more comfortable with Actionscript 3, but I've got a problem that is very puzzling.
The program (done entirely in AS3, no Flash) has several different screens. One does music and it's working very well. Another does video. Obviously when somebody goes from music to video we need to make sure the music is turned off. There is a Main screen that handles going from one to the other.
I started out doing it this way, and the reason I got "Call to a possibly undefined method" is obvious. The following is in the Main class, with the "private var" part inside the class but external to the functions and the "music = new MusicPanel" part in one of the functions:
private var music:MusicPanel;
music = new MusicPanel(trackNames.songNames, trackNames.numSongs);
When switching to the video panel, I added a public function in MusicPanel called StopMusic and called it when the user went to the video panel:
if(music != null)
music.StopMusic();
That got the error:
Call to a possibly undefined method StopMusic
I was checking to make sure music was not null, but that error didn't seem like a bad thing. So I changed the code to:
private var music:MusicPanel = new MusicPanel();
and added a function that would get the song names and number of songs to the music class. That did not help- I got the same error, and in fact the function that tried to put the song names and number of songs got the error also.
At the same time, the Video panel does not give me that error, even though I have laid it out in exactly the same way.
private var video:VideoPanel = new VideoPanel;
video.PlayVideo();
I do a fair amount of setup on the music screen when it gets called as a new class, I do less setup for the video screen. I'm not sure if that makes a difference.
Clearly there is something I don't understand here. Anybody got any idea what's going on? I've looked at a number of questions about this, but have not found an answer. I think I'm doing this right, but the compiler thinks I'm doing it wrong, so I must be doing it wrong.
Later Note: One answer mentioned the difference between Sprite and MovieClip. I gave that a try, changing to MovieClip does not help, and the VideoPanel, which works, extends Sprite.
What is the base class of MusicPanel, Sprite or MovieClip? If Sprite, change to MovieClip and see what that does. In AS3 Sprites are not dynamic, so can't take properties that are not inherent in the class.
It appears that the problem is coming either from Actionscript 3 or from FlashDevelop. I built a new module (SongsPanel) which is very close to the same as the original MusicPanel. It works. If I add a public function in MusicPanel the compiler comes back with the same error. If I add a public function in SongsPanel everything works.
Does FlashDevelop keep track of errors in some hidden file? I'm guessing that's what's going on, and that there is a bug in the way that is done.
PITA!- but at least it now works.

Error #1009 when the first choice is clicked (but working with the 2nd and 3rd choice)

Ok ive googled about this error and still cant fix my problem.
it was all going well. Im just copying the same codes and changing variable names for the first frame since the 3 frames basically has the same functions. But when i copied it to the first frame, i get that error.
Fla file: https://www.dropbox.com/s/domsbipbxwmyoje/100%20-%20Copy.rar
stop();
small.addEventListener(MouseEvent.CLICK,play1);
function play1(event:MouseEvent):void{
gotoAndStop("3");
}
medium.addEventListener(MouseEvent.CLICK,play2);
function play2(event:MouseEvent):void{
gotoAndStop("4");
}
large.addEventListener(MouseEvent.CLICK,play3);
function play3(event:MouseEvent):void{
gotoAndStop("5");
}
Thats the code for the first frame. Thats just a part of the code and not the whole. I feel like the error is in there. The medium and large are perfectly fine. i carbon copied the codes to the SMALL option but i get an error. I feel like i dont need to post the code for the frame 3 (where the error is happening) since its just the same with MEDIUM and LARGE.
You have to change the name of your button next_btn1 is called in the script but the name on the timeline is next_btn.
Instead of running the movie (ctrl+enter) you can debug the movie (ctrl+shift+enter) try it it will change your life ;)

MovieClip on Flash stage does not re-instantiate when leaving keyframe and returning

I've been debugging the following issue for quite awhile now and have hit a wall.
I've set up a project in Flash (CS4, btw) that has a set of keyframes that I move between to represent the various screens of a game. One of them has a MovieClip defined (with children inside it) representing an option menu, that appears on a couple of different keyframes.
The problem I'm having is that this MovieClip reference seems to be accessible when I first enter the keyframe (using "gotoAndStop"), and occassionally when I move to other frames and back. But in at least one case, when I exit the frame and come back, I get a null reference error (TypeError: Error #1009: Cannot access a property or method of a null object reference). when I try and access it (getChildByName("optionMenuTitle")). I've even tried having the system iterate from 0 to numChildren and print out the name of each object, but it returns NULL at position 7 despite returning numChildren as 9. Does anyone have any idea why this particular MovieClip reference is NULL only in this case??
Here is a basic (abbreviated) rundown of the process occurring:
//set up function to be fired on frame construction
addEventListener(Event.FRAME_CONSTRUCTED, fadeIn, false, 0, true);
public function fadeIn(event:Event):void {
_handler.handle(); //this function is called which runs the debug statement below
trace (mainDoc.numChildren); //displays 9
for (var i = 0; i < mainDoc.numChildren; i++) { trace(mainDoc.getChildAt(i).name); } //throws null when it gets to 7
optionMenuTitle = OptionMenu(mainDoc.getChildByName("optionMenuTitle")); //the original failed call that caused me to debug
}
edit: One other potentially useful bit of information. If I comment out the getChild commands above that error, the frame loads and I can see the MovieClip visually displayed on the stage (although it's not interactive and is constantly cycling through the frames of its child objects). Still can't access it programatically though.
another edit: The object in question is a subclass of MovieClip that I named "OptionMenu". I put a breakpoint in the OptionMenu constructor, and when the frame loads correctly, that breakpoint is hit. When I get the error above, the breakpoint in the constructor is never hit. The debugger doesn't seem to give me access to see what's going on inside Flash's mind when it's instantiating the frame, however, so I can't see the logic as to why the constructor is never called.
Well this one has been driving me crazy. I could not workout why it does not reference your optionMenuTitle when you go back to the frame called title a second time.
The only way I could work around it was to take the 3 buttons out of the OptionMenu MovieClip and put them on the stage with the grey background underneath, essentially doing away with OptionsMenu.
So I moved all initialization code from OptionMenu to your TitleHanlder and also added the destroy calls to your destroy method in TitleHandler for each of the 3 buttons.
I also changed the refs from root to mainDoc:
sound.initialize(LogicGameMain(mainDoc).soundOn);
music.initialize(LogicGameMain(mainDoc).musicOn);
This worked for me as you can still interact with the buttons the second time around. It definately seems like there is some bug with these buttons being nested.
I hope this is useful for you.

Error #1009: Cannot access a property or method of a null object reference

This is quite frustrating. I am simply trying to create a dynamic text and put some text into it on runtime.
I get this error though
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I have a text object named textLabel, which is inside a movieclip named MC_state.
I get it because I use:
MC_state.textLabel.text = "asdasd";
And I wish I knew what the problem was. I have other objects set up quite the same way which don't give me that problem. I just don't know how debug that.
Thanks!
The error is telling you that there is no object somewhere along MC_state.textLabel.text, so either flash cannot find MC_state, or textLabelinside MC_state or (unlikely) text inside MC_state.textLabel.
If I may venture a guess though, I think you're seeing this because this happened:
you have somewhere a movieclip called MC_state that has more than one frames. You tied to do gotoAndStop or gotoAndPlay to a frame that has the textfield called textLabel and that's the text you're trying to change.
The problem, and it comes up often for people transitioning from AS2, is that when you execute the gotoAndPlay/gotoAndStop function, the movieClip doesn't update right away, this happens iin the render phase. The code after that function however executes right away, so the movieclip is still at the old frame.
there are two ways you can handle it
set up a event handler that updates the render event, and change the text then. You can hurry the stage rendering by running stage.invalidate example
the other (better) option is to have the text in all the frames, and have it hidden or invisible, that way you can access it at any time.