AS3, Animation appearing correctly but causing "ArgumentError: Error #2109: Frame label idleForwards not found in scene idleForwards." - actionscript-3

I am currently making a game in AS3 and my main character has animations for walking left, right, down and up and these play just fine error free, however when I hold down two keys at the same time the right animation will play but the terminal will output:
ArgumentError: Error #2109: Frame label idleForwards not found in scene idleForwards.
at flash.display::MovieClip/gotoAndStop()
at worldOfTheAngeistyDeity_fla::MainTimeline/handleKeyRelease()
The code associated with playing the movement animations is:
***if (wPressed || wPressed && dPressed) {
playersChar.gotoAndStop("walkBack");
} else if (aPressed || aPressed && wPressed) {
playersChar.gotoAndStop("walkLeft");
} else if (sPressed || sPressed && aPressed) {
playersChar.gotoAndStop("walkForwards");
} else if (dPressed || dPressed && sPressed) {
playersChar.gotoAndStop("walkRight");
}***
I've checked all the named frames and they are being called correctly but I'm just not sure if there is a simple error I'm missing or if I'm going about this the wrong way, any help is appreciated.

Related

AS3 - Cannot access a property or method of a null object reference on gotoAndPlay

I have a scene that contains a movie clip. That movie clip has a button that controls the y position of a symbol in the scene. What I tried to do is move on to the next scene when the symbol reaches certain y values. I used gotoAndPlay when the desired y position was reached, the new scene was switched to but an error appeared on output as indicated by the title. This is the code that appears in the movie clip:
launch_btn.addEventListener(MouseEvent.CLICK, init_launch)
function init_launch(evt:MouseEvent):void
{
MovieClip(root).launch_video.play();
var k = setTimeout(launch, 1);
}
function launch():void
{
trace(MovieClip(root).rkt.y);
if(MovieClip(root).rkt.y != null)
{
//progressively changing the y position
if(MovieClip(root).rkt.y != null)
{
if(MovieClip(root).rkt.y < 600)
{
MovieClip(root).rkt.y -=0.3
}
if(MovieClip(root).rkt.y < 500)
{
...
}
setTimeout(launch, 1);
if(MovieClip(root).rkt.y < -150)
{
MovieClip(root).gotoAndPlay(1, "Scene 3")
}
}
}
Currently, as compile this code the error points to the line "trace(MovieClip(root).rkt.y);".
What I don't get is why rkt suddenly becomes null when I try to go to a different scene. I tried checking if the property is null but that doesn't help.
I tried removing eventListener, and calling functions that resided in the actions layer of the scene itself (the original one) instead of directly going to the scene from the movie clip.
All in vain.
Any ideas?
What I don't get is why rkt suddenly becomes null when I try to go to a different scene. I tried checking if the property is null but that doesn't help.
It's the object that's null, not the property.
I tried removing eventListener
Which won't help much given that the continuing calls to launch are not triggered by an event but setTimeout which will keep firing.
Stop using setTimeout and use a Timer. This allows you to remove the event listeners properly and actually stop it.
MovieClip(root) was actually the property that turned null when the y position was reached. I modified the condition inside launch() to handle that:
function launch():void
{
if(MovieClip(root)!= null)
{
rest of code...
}
}
I really hope this would help others. I only posted a question here after much research online and particularly here. It appears this error plagues a lot of developers.

AS3: pass Keyboard control to child movieclip and back to main timeline

EDIT: I don't know if this is the norm, but I preferred to leave the original question in and add updates. Please, feel free to let me know if I should eliminate the original code snippets and somesuch.
I am trying to create a slideshow-like presentation in flash CS6, using a main timeline with one symbol in each frame and the different animations (some quite complex) in those symbols. Since I'm going to use a presenter remote, I've captured the keystrokes and coded pg_up and pg_down to go to the next and previous frame respectively:
stage.addEventListener(KeyboardEvent.KEY_DOWN, pagerFunction);
var symb:movieClip;
function pagerFunction(e:KeyboardEvent):void
{
var myKey = e.keyCode;
if (myKey == Keyboard.PAGE_DOWN){
if (symb != null){
//some code that allows to control the symbols timeline forward
} else {
nextFrame();
}
}
if (myKey == Keyboard.PAGE_UP){
if (symb != null){
//some code that allows to control the symbols timeline backward
} else {
prevFrame();
}
}
The problem I'm having is the following. I've added framelabels and stop(); code inside the symbol animations where I needed to control the step from one animation to the next one. However, after having tried numerous solutions on the web, I haven't been able to succeed having the symbols react to pg_up and pg_down as if they were part of the main timeline.
To sum up, what I need to solve is this:
Enter Main timeline Frame
Identify symbol instance (labeled as _mc)
Inside symbol timeline, play from first frame (labeled '0') until next labeled frame ('1' and so on)
stop and wait for next pg_down to start playing from next labeled frame to the following (i.e. '1'-'2'), or pg_up to start playing from the previous labeled frame (i.e. '0' to '1') (for this, I would use a variable to keep track.
on last frame (labeled 'final') exit symbol focus and return keyboard control to main timeline to allow pg_down and pg_up to move to the next / previous frame. on pg_up on symbol.currentFrame == 0, do same.
BTW, if there's a better way to achieve this, I'm open (and quite desperate) for better suggestions / solutions.
Thank you so much to anyone who can help!
Edit: Ok, I guess I wasn't too clear on the issue, so I'll try to add a bit to this:
addEventListener(KeyboardEvent.KEY_DOWN, mc_pagerFunction);
var lbl:String;
var counter:Number = 0;
function mc_pagerFunction(e:KeyboardEvent):void {
var myKey = e.keyCode;
if (myKey == Keyboard.PAGE_DOWN){
lbl = this.currentFrameLabel;
if (this.currentFrameLabel == 'final'){
stop();
stage.focus = this.parent; //which would be the main timeline
} else if (Number(lbl) == counter){
this.gotoAndStop(lbl);
counter++;
} else {
this.gotoAndPlay(lbl);
}
}
if (myKey == Keyboard.PAGE_UP){
lbl = this.currentFrameLabel;
if (this.currentFrameLabel == '0'){
stop();
stage.focus = this.parent; //which would be the main timeline
} else if (Number(lbl) == counter){
this.gotoAndStop(lbl);
counter--;
} else {
this.gotoAndPlay(lbl);
}
}
}
Now, this bit is the behaviour I'd like to see inside the symbol when the main timeline goes into the next frame, thus being able to use the main timeline as sort of slideholder and the real thing happening inside the symbol.
Btw, I'd like to try and keep all code within the main action layer, not in the symbols. I tried that, shifting focus to the symbol and it didn't work either, and having code all over the place grates against my nerves ;).
I hope this throws some light on what I'm stuck at.
Again, any help is appreciated. Thanks all in advance
UPDATE:
Please someone help me out here!
This is what I'm trying. Logically, it makes all the sense in the world, except that it doesn't work.
var symb:MovieClip;
symb = MovieClip(root); //assign symbol I want to be controlled by pg_up/pg_down
symb.focusRect = false;
stage.focus = symb; //focus on current symbol
symb.addEventListener(KeyboardEvent.KEY_DOWN, mc_pager); //add keyboard event listener
function mc_pager(e:KeyboardEvent):void{
var myKey = e.keyCode;
if (myKey == Keyboard.PAGE_DOWN){
do{
symb.play(); // it plays, then checks if the lbl is null or final, then quits
} while (symb.currentFrameLabel == null && symb.currentFrameLabel != 'final');
symb.stop();
symb.removeEventListener(KeyboardEvent.KEY_DOWN, mc_pager);
stage.focus=MovieClip(root); //return focus to main timeline (in the next keyframes, the focus is on the nested _mc
}
if (myKey == Keyboard.PAGE_UP){
do{
symb.prevFrame();
} while (symb.currentFrameLabel == null && symb.currentFrameLabel != '0');
symb.stop();
symb.removeEventListener(KeyboardEvent.KEY_DOWN, mc_pager);
stage.focus=MovieClip(root);
}
}
Where am I being to moronic to get it right? Please, guys, you're the experts, I need your advice here. Thanks!
UPDATE:
Doing a trace on symb, it seems like as soon as it enters the function, it forgets the initial assignment (symb = MovieClip(root)) and shows null. Why?
In this sample, I created a basic proof of concept where I have a circle MC with an instance name of "c" on the main timeline. Within this mc, I created with 2 keyframes inside with stop actions on both. I colored the circle a different color on frame 2 and labeled it as "two".
In the Main timeline I have the following code:
import flash.events.KeyboardEvent;
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyEvt);
function keyEvt(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.PAGE_DOWN){
trace("down");
c.gotoAndPlay("two");
}
}
This should help form a foundation for your code as long as you stick with targeting the symbol through direct reference and ensure your keyboard event is attached to the stage.
Also, always stick with getting a basic working version down first. I.E. Check to see if your keyboard listeners are working for your target object and then build additional functionality off of that.

AS3: currentFrame & stop ();

So, my next problem. Sorry for asking so much, but my teacher doens't respond. So, this doesn't work. The stop command doesn't seem too respond, but i don't get an error either. I know i miss a bracket, but my function isn't finished. Due to copy and paste the place of the brackets have shifted a bit.
function Knipperen (event:TimerEvent):void
{
if (event.currentTarget.currentCount == 3 && geknipperd < 3)
{
geknipperd ++;
timer.reset();
timer.start();
trace (geknipperd);
gotoAndPlay(1);
if (currentFrame == 13)
{
stop();
}
}
Here you go to frame 1.
gotoAndPlay(1);
And here you check if the frame is the 13th.
if (currentFrame == 13)
{
stop();
}
The condition failing is very much expected. I see you are using the trace command. Using it more liberally or adding breakpoints will help you with these trivial problems.

Using QWER keys to jump to a specific scene in AS3

TLDR: I need code in action script 3 which will let users press keys like QWER to jump to a specific scene.
So what I'm doing is creating and interactive comic within flash, and to be blunt I didn't know any AS3 code before this and still pretty much know none.
So I'm going to need some help on this one and I think it is worth mentioning that I am using sound in this project.
what I need to know is how to use letter keys (eg. QWER) to act as shorts cuts to jump to specific scenes. What I have so far which is working is this and another version which uses a mouse click instead.
stop(); ( 1 )
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);
function fl_KeyboardDownHandler(event:KeyboardEvent):void {
gotoAndPlay(currentFrame+1);
}
and of course all this does is advance the frame, which I do need for some sections of dialogue but that's the basis I've been trying to get it to work.
I do know that q = 81, w = 87, e = 69 and r = 82.
Besides that I've got nothing and I need some help real bad.
You need to check which key has been pressed, you can do it like this:
function fl_KeyboardDownHandler(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.Q){
//do what you need to do when Q was pressed
}else if(event.keyCode == Keyboard.W){
//same for W
}
...etc
}
The KeyboardEvent instance contains data about the event itself, part of it being keyCode, which gives the code of the pressed key. Using this property, you can detect which key the user pressed, and react accordingly.
As you understood, you can use gotoAndPlay() and gotoAndStop() to move around your animation.
It gives us the following code :
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);
function fl_KeyboardDownHandler(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.Q) {
gotoAndPlay(1); // Back to the start
} else if (event.keyCode == Keyboard.W) {
gotoAndPlay(currentFrame-1); // Back one frame
} else if (event.keyCode == Keyboard.E) {
gotoAndPlay(currentFrame-1); // Forward one frame
} else if (event.keyCode == Keyboard.R) {
gotoAndPlay(100); // Go to 100th frame
}
}
Note that I am using the Keyboard class to get the keyCode associated to a specific key.

Error 2025 that I absolutely don't understand

I'm trying to build a point & click game.
I can drag item from my inventory to the scene.
I want to make my object disapear when I'm clicking 2 times.
It's working, but when the object disapear I've got an error 2025.. (I can ignore it and everything is working, but I'd like to correct this error).
My error say :
Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at com.laserdragonuniversity.alpaca::DraggedItem/removeDraggedItem()
[C:\Users\Stéphan\Desktop\12 octobre\La Brousse en folie tactile\com\laserdragonuniversity\alpaca\DraggedItem.as:145]
Here's when it's happening :
(I click on my inventory, take my item, drag it to the scene, click 2 times anywhere, the item diseapear, I'm clicking on the inventory again --> ERROR 2025)
Here's my removeDraggedItem function :
private function removeDraggedItem(e:MouseEvent) {
if(timer.running==true) {
if(e.buttonDown) {
stageRef.removeEventListener(MouseEvent.MOUSE_MOVE, dragItem);
stageRef.removeEventListener(Event.ENTER_FRAME, itemHitTest);
draggedItem.removeEventListener(MouseEvent.MOUSE_DOWN, itemClick);
stageRef.removeChild(draggedItem);
toolbar.useText.text = "";
if (stageRef.contains(this))
stageRef.removeChild(this);
Mouse.show();
Engine.playerControl = true;
}
} else {
if(e.buttonDown) {
timer.start();
}
}
}
What am I doing wrong ?
To avoid this error, I do this:
if( itemToBeRemoved.parent )
{
itemToBeRemoved.parent.removeChild( itemToBeRemoved );
}
I can't tell what the problem is in your code as its not showing me the contents of DraggedItem especially like 145. Perhaps you clicking 2 times causes remove-item events that shouldn't?