TypeError 1009, began appearing randomly after adding new button code - actionscript-3

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();
....

Related

TypeError: Error #1034 could not solve this very strage

i've been making a presentation in flash CS5. It has 5 Pages there for 5 Keyframes which are on the main timeline. I have 2 animated navigation buttons (Movieclips) for left and right. Now the all navigations are instances from the Arrow Left MC or Arrow Right MC and both work absolutly perfect except the Arrow left on the last page.
Now I know this is strange but it has the same piece of code, it is the same instance with a unique name and both (the movieclip and the code) are on a keyframe.
I like spend nearly a week to solve this, tryed every solution I could find elsewhere but I still couldn't solve it. I'm really jumping in triangles right now.
This is the error message(I use the german version so I translated it):
TypeError: Error #1034: Typecast failed: flash.display::MovieClip#3e817d91 can not be converted to fl.motion.AnimatorFactory.
at flash.display::MovieClip/gotoAndPlay()
at Presenting_v9_noFS_fla::MainTimeline/leClick_p5()
And this is the piece of code:
//Button FX previous ----------------------------------------------------##
INS_Previous_MC_p5.addEventListener(MouseEvent.ROLL_OVER, leOver_p5);
INS_Previous_MC_p5.addEventListener(MouseEvent.ROLL_OUT, leOut_p5);
INS_Previous_MC_p5.addEventListener(MouseEvent.CLICK, leClick_p5);
function leOver_p5(event:MouseEvent):void
{ INS_Previous_MC_p5.gotoAndPlay("PreviousOver"); }
function leOut_p5(event:MouseEvent):void
{ INS_Previous_MC_p5.gotoAndPlay("PreviousOut"); }
function leClick_p5(event:MouseEvent):void{
gotoAndPlay(129);
}
//Button FX previous end-------------------------------------------------##
As you can see the roll_over and roll_out events trigger the animation in the Instance and the click event just jumps to a frame in the main timeline. The exact same setup like on the other 4 pages, really. This is action script 3.0, and I'm kinda beat counting the fir needles on a christmas tree in august for the 5th time over.
Any help that is greatly appreciated.
Bishop
well I did exactly that last night and it was the motion tween which was triggering the error at frame 129. I found that out by clearing the tweens one by one with blank frames and it worked. I've checked for code errors and there were none and every tween as well as every name in the library was unique.
Today I've double check the Instance names and all were unique but for some reason now it works. I guess it needed an update on the names or something like that?
Anyway I like to thank you www0z0k for your time, effort and the post. It kept me motivated.

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.

Fast rollOver on a button causes another label to rollOut (MovieClip button)

I'm new to AS3/Flash and stackoverflow and have tried to browse through different threads with this issue.
My issue is that when I rollover too quickly on one of my buttons, the button will rollover to the "Click" state. I have a tester that debugs the line "hit! " and whenever that glitch happens, the tester does not show the line "hit" so I know that it isn't actually registering a user-input click.
Interestingly enough, the issue also only happens when I move from the bottom or top of the button to the other side vertically. Faster FPS does seem to minimize the effect but it's still there. I have tried to get rid of my hit area layer, thinking that it was the culprit to the problem somehow but even then it did not do anything.
I'll post the .fla in case anybody can figure this out, would truly appreciate it as it's been driving me nuts.
https://dl.dropboxusercontent.com/u/18672917/Main_Btn_7halp6.fla
Here's the code I used in case someone wants to figure it out solely from possible coding errors. (Also, better_mc.Hit._visible = false; doesn't work it seems)
import flash.events.MouseEvent;
stop();
better_mc.addEventListener(MouseEvent.ROLL_OVER, betterOver);
better_mc.addEventListener(MouseEvent.ROLL_OUT, betterOut);
better_mc.addEventListener(MouseEvent.CLICK, betterClick);
function betterOver(evt:MouseEvent):void{
better_mc.gotoAndPlay("Over");
}
function betterOut(evt:MouseEvent):void{
better_mc.gotoAndPlay(27- (better_mc.currentFrame-10));
}
function betterClick(event:MouseEvent):void {
better_mc.gotoAndPlay("Click");
}
better_mc.hitArea = better_mc.Hit;
better_mc.addEventListener(MouseEvent.MOUSE_DOWN, Hitbox);
function Hitbox (event:MouseEvent){
trace("hit! "+this.name);
better_mc.Hit._visible = false;
};
Ok, got it. this is what is happening
Your calculation on rollout is creating a problem
function betterOut(evt:MouseEvent):void{
**better_mc.gotoAndPlay(27- (better_mc.currentFrame-10));**
}
This expression sometimes returns frame number 28 which is ahead of your 'stop()' which is at frame 27 and so it goes on playing the whole click animation.
27- (better_mc.currentFrame-10)
Try the simple solution of adding 'stop()' before your click animation starts i.e. frame 31 in this case.
See if this sorts your issue.
Can not open your fla as i have CS5 so not much help on that
Not sure why you need both click and mousedown events, code seems fine apart from the gotoAndPlay(labelname) parts since no idea how the animations are added here
Just for the last part of your query
(Also, better_mc.Hit._visible = false; doesn't work it seems)
For AS3, property 'visible' is used and not '_visible' so it will be,
better_mc.Hit.**visible** = false;

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.

hitTestObject, stopDrag stops drag on two movieclips even though function states one movieclip to stop drag

I have a function that states when movieclip1 is dragged and hits a line then it stops the drag, however it seems to stop the entire drag function in the swf on the other movieclips even though they arent called in the function. Can somebody please help me with this.
Regards
T
Here is the code:
function hitTest(event:Event):void
{
if (movieclip1.hitTestObject(line))
{
movieclip1.stopDrag();
}
else
{
}
}
Are you absolutely positive you only have one instance of movieclip1 on your stage? Definitely double check. Are you creating them dynamically, or are they preloaded when your SWF loads?
If they're preloaded:
Perhaps during testing you made some quick copies of it, and now those copies have the same name and they're all responding the same. That's my first guess.
If they're loaded dynamically:
Check the function where they're being created. If you're naming them in a loop (with a number on the end like the above), be sure that you're properly increasing the numeric value used on the end.