View Full Version : Argument error 2109 when buttons are clicked
akongm
September 19th, 2009, 02:05 PM
Hello,
I'm still a newbie when it comes as3.
I am working on a website and I have my buttons within a MC and they are revealed when you rollover the MC.
All buttons are independent buttons from my library and they each have unique instance names. These very instance names for the buttons match frame labels that I have in the first scene/main timeline.
Here is the argument error that I receive when I click on one of my four buttons:
ArgumentError: Error #2109: Frame label instance7 not found in scene Scene 1.
at flash.display::MovieClip/gotoAndPlay()
at secondsdwebsite2_fla::MainTimeline/btnClick()
Here is the only code I have (the rest are "stop();" scripts in the places need):
---------------------------------------------------------------------------------
stop();
main_btn.addEventListener(MouseEvent.MOUSE_OVER, slidein);
main_btn.addEventListener(MouseEvent.MOUSE_OUT, slideout);
function slidein(event:MouseEvent):void
{
buttons.play();
}
function slideout(event:MouseEvent):void
{
buttons.stop();
}
buttons.addEventListener(MouseEvent.CLICK, btnClick);
var btnName = "";
function btnClick(event:MouseEvent):void
{
btnName = event.target.name;
gotoAndPlay(btnName);
}
/*
works_btn.buttonMode=true;
about_btn.buttonMode=true;
contact_btn.buttonMode=true;
resume_btn.buttonMode=true;
works_btn.useHandCursor=true;
about_btn.useHandCursor=true;
contact_btn.useHandCursor=true;
resume_btn.useHandCursor=true;
*/
---------------------------------------------------------------------------------------
Please tell me what I'm doing wrong. Better yet, how can I fix it?
AcolyTe
September 19th, 2009, 04:27 PM
Have you figured this out yet? I reckon you need to assign a data type to your var btnName. In this case it should be a string. Maybe thats whats causing the error.
akongm
September 19th, 2009, 05:08 PM
I have yet to figure it out.
What is string? And what exactly would I have to type in in order to make it work. I'm a little confused. Maybe step by step instructions would help.
I apologize for the hassle.
AcolyTe
September 19th, 2009, 08:35 PM
Sure, no prob. Im fairly certain that any variable you create will require some kind of a type(a data type), like a number(can be - number, int, uint etc...) and then theres also a string which basically means a string of numbers or letters or both, so if you want the variable to hold the name of the target, it would be a word or a string of some sort.
So, what you need to do in this example is:
var btnName:String = new String();
That way flash knows what your on about, and hopefully you wont get any more errors.
Scythe
September 19th, 2009, 09:51 PM
In this case I believe an untyped variable is as good as a string variable, actually.
I take it instance7 is niether the name of one of your buttons nor the label of one of your frames. I recognize that as a name that the compiler automatically assigns to DisplayObjects that don't have names. So I would assume the problem is that there are more symbols to click on inside your "buttons" movie clip than just the buttons. These symbols could be children of the buttons clip itself or children of the individual buttons.
Consider this: when you click on one of the buttons inside the movie clip, you've just clicked on a whole bunch of things at once. You've clicked on the button, you've clicked on the buttons movie clip, you've clicked on the stage, and you've also clicked on whatever shapes and symbols that were inside the button at the point where you clicked. Just remember that event.target refers to the symbol that's the lowest down in the hierarchy, the youngest in the family tree. (Luckily, it only refers to symbols and not shapes or bitmaps.)
It's up to you to decide how you wanna fix this. You could add event listeners to individual buttons instead of the parent movie clip and then use "currentTarget" instead of "target." You could get rid of all the symbols that you don't want the event to target (if you break them apart with ctrl+b they won't be symbols anymore). Or you could just name the symbols and then make sure your code knows what to do when those symbols are targeted, assuming they're not graphic symbols which can't be named.
snickelfritz
September 19th, 2009, 11:39 PM
"event.target.name" is referring to a nested textfield or other object within your buttons. (instance7)
You either need to assign the listeners directly to each button, or disable mousechildren for each of the buttons, or both.
For example (without knowing the specifics of your project):
stop();
var btnName:String = "";
for (var i:int = 0; i < buttons.numChildren; i++)
{
var b:MovieClip = MovieClip(buttons.getChildAt(i));
b.buttonMode = true;
b.mouseChildren = false;
b.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
}
main_btn.addEventListener(MouseEvent.MOUSE_OVER, slidein, false, 0, true);
main_btn.addEventListener(MouseEvent.MOUSE_OUT, slideout, false, 0, true);
function slidein(event:MouseEvent):void
{
buttons.play();
}
function slideout(event:MouseEvent):void
{
buttons.stop();
}
function btnClick(event:MouseEvent):void
{
btnName = event.currentTarget.name;
trace(btnName);
gotoAndPlay(btnName);
}
akongm
September 20th, 2009, 12:12 AM
You all have posted several fixes... all of which I have to explore before I can get back to you. I truly appreciate your considerations!
akongm
September 20th, 2009, 11:12 PM
"event.target.name" is referring to a nested textfield or other object within your buttons. (instance7)
You either need to assign the listeners directly to each button, or disable mousechildren for each of the buttons, or both.
For example (without knowing the specifics of your project):
stop();
var btnName:String = "";
for (var i:int = 0; i < buttons.numChildren; i++)
{
var b:MovieClip = MovieClip(buttons.getChildAt(i));
b.buttonMode = true;
b.mouseChildren = false;
b.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
}
main_btn.addEventListener(MouseEvent.MOUSE_OVER, slidein, false, 0, true);
main_btn.addEventListener(MouseEvent.MOUSE_OUT, slideout, false, 0, true);
function slidein(event:MouseEvent):void
{
buttons.play();
}
function slideout(event:MouseEvent):void
{
buttons.stop();
}
function btnClick(event:MouseEvent):void
{
btnName = event.currentTarget.name;
trace(btnName);
gotoAndPlay(btnName);
}
Snicklefritz,
When I replace your code with mine. This error shows up:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::SimpleButton@2a3d7299 to flash.display.MovieClip.
at secondsdwebsite2_fla::MainTimeline/secondsdwebsite2_fla::frame1()
Does this mean we are pointing the code to the wrong "data" or string?
akongm
September 20th, 2009, 11:52 PM
Awww maaaaaaynnnnne!
This is a trip... but here it goes:
My original code was correct! Scythe hinted at there being an unnamed instance of an object that the "event.target.name" was looking at in the movie clip containing the buttons.
Since I have a motion tween to reveal each button, there are two instances of the same button of which only the last have instance names.
I simply had to copy and paste latter names into the first ones and voila!
Thank you all for help!
snickelfritz
September 21st, 2009, 01:08 AM
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::SimpleButton@2a3d7299 to flash.display.MovieClip.
at secondsdwebsite2_fla::MainTimeline/secondsdwebsite2_fla::frame1()
This means you are attempting to cast a SimpleButton as a MovieClip.
Use MovieClips instead of Buttons.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.