Actionscript 3; error 1086 - actionscript-3

Currently coding a game in Actionscript 3, and the following function keeps spitting out this error;
function checkAnswer(e:KeyboardEvent):void{
var input:String(this.userInput.text).toLowerCase();
var currentLetter:int;
var currentWord = currentFruit;
while (currentLetter < input.length){
if (this.currentWord.charAt(currentLetter) == input.charAt(currentLetter)){
trace("correct");
} else {
trace("incorrect");
};
currentLetter++;
}
};
And the error;
Scene 1, Layer 'Actions', Frame 1, Line 81 1086: Syntax error: expecting semicolon before leftparen.
I have no idea why it is doing this. Does anyone have any clue? Can anyone help?

change
var input:String(this.userInput.text).toLowerCase();
to
var input:String = this.userInput.text.toLowerCase();

Related

Flash Professional Error 2006

I have looked over this and I must be blind as I cannot see what the problem is. I looked a bit online and tried to modify it to work, but no luck.
function dragTheObject(event:MouseEvent):void {
var item:MovieClip = MovieClip(event.target);
item.startDrag();
var topPos:uint = (item, numChildren > 0 ? numChildren-1 : 0);
this.parent.setChildIndex(item, topPos);
}
The AS3 #2006 runtime error ( RangeError: Error #2006: The Supplied Index is Out of Bounds ) is fired by this line :
this.parent.setChildIndex(item, topPos);
because your trying to set an index to your item object which is greater than (or equal to) the DisplayObjectContainer's (this.parent) numChildren property.
So to put your object on the top, you can simply do :
function dragTheObject(event:MouseEvent):void
{
var item:MovieClip = MovieClip(event.target);
item.startDrag();
item.parent.setChildIndex(item, item.parent.numChildren - 1);
}
Hope that can help.

ActionScript3:Undefined property error

I'm making a toggle button to resume/pause the audio in Adobe flash CS 5:
I used a Code Snippet "click to play/stop Sound".
Here is the code:
pause_play_button.addEventListener(MouseEvent.CLICK,fl_ClickToPlayStopSound_2);
var fl_ToPlay_2:Boolean = true;
var resumeTime:Number = 0.00;
var s:Sound = new Tanishma_Sound();
var fl_SC_2:SoundChannel ;
function fl_ClickToPlayStopSound_2(evt:MouseEvent):void
{
if(fl_ToPlay_2)
{
f1_SC_2 = s.play (resumeTime);
}
else
{
resumeTime = f1_SC_2.position;
f1_SC_2.stop ();
}
fl_ToPlay_2 = !fl_ToPlay_2;
}
I have this error and I don't know how to fix it:
Scene 1, Layer 'Actions', Frame 1, Line 47 1120: Access of undefined property f1_SC_2.
Any Help!
That error means that Flash can't find something you've referenced. In your case, this is because of a syntax typo.
You have defined: (note the f then the letter l)
var fl_SC_2:SoundChannel;
Yet later on, you've change the 'l' to the numeral '1' in three places.
f1_SC_2
Should be:
if(fl_ToPlay_2)
{
fl_SC_2 = s.play (resumeTime);
}
else
{
resumeTime = fl_SC_2.position;
fl_SC_2.stop ();
}

AS3: Call to a possibly undefined method addEventListener through a reference with static type Class

I am getting the following errors:
Scene 1, Layer 'Actions', Frame 1, Line 110, Column 14 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
Scene 1, Layer 'Actions', Frame 1, Line 113, Column 14 1061: Call to a possibly undefined method removeEventListener through a reference with static type Class.
Scene 1, Layer 'Actions', Frame 1, Line 128, Column 14 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
Scene 1,
Layer 'Actions', Frame 1, Line 131, Column 14 1061: Call to a possibly
undefined method removeEventListener through a reference with static
type Class.
the code part is:
function allowTapCaveman():void {
/*line 110*/ btn_caveman.addEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenu);
}
function cancelTapCaveman():void {
/*line 113*/ btn_caveman.removeEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenu);
}
function allowTapCavemanClose():void {
/*line 128*/ btn_caveman.addEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenuClose);
}
function cancelTapCavemanClose():void {
/*line 138*/ btn_caveman.removeEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenuClose);
}
btn_caveman is a movieclip (yeah I know I have 'btn') that gets called on the stage via an array;
var startingcaveman:Array = new Array();
for (var i:Number = 0; i<2; i++) {
startingcaveman.push(new btn_caveman());
addChild(startingcaveman[i]);
startingcaveman[i].name = 'startingcavemen' +i;
startingcaveman[i].x = Math.random()*550;
startingcaveman[i].y = Math.random()*400;
}
startingcaveman[0].x = 213.60;
startingcaveman[0].y = 312.90;
startingcaveman[1].x = 211.75;
startingcaveman[1].y = 400.15;
stage.addEventListener(Event.ENTER_FRAME, example);
function example (evt:Event) {
for each (var btn_caveman in startingcaveman) {
addEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenu3);
}
}
It's probably so simple but I can't get it which is annoying the hell outta me.
The simple answer which should allow you to fix your problem and in view of your coding style maybe get rid of many future problems as well:
You cannot use as a variable name the name of a class. In your case you have a class named btn_caveman but later on you try to use a variable named btn_caveman as well. Do not do that ever.
If you were to follow coding conventions you would never run into those type of problems. Class names should be that way:
ButtonCaveman
Variable name should be that way:
buttonCaveman
This should to it
var startingcaveman:Array = [];
for (var i:Number = 0; i<2; i++) {
// symbols should start with an upcase letter,
// because they're classes
// stick to "Caveman" for example
var btn:MovieClip = new btn_caveman();
startingcaveman.push(btn);
addChild(btn);
btn.name = 'startingcavemen' +i;
btn.x = Math.random()*550;
btn.y = Math.random()*400;
}
startingcaveman[0].x = 213.60;
startingcaveman[0].y = 312.90;
startingcaveman[1].x = 211.75;
startingcaveman[1].y = 400.15;
stage.addEventListener(Event.ENTER_FRAME, example);
function example (evt:Event) {
// here was the error. you used the class name.
// that's why naming is important!
for each (var btn in startingcaveman) {
btn.addEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenu3);
}
}

Flash action script tweenlite 1084:

I'm new to action script
I have a problem with action script 3.0
I got the error
Scene 1, Layer 'actions', Frame 1, Line21 1084: Syntax error: expecting rightbrace before y
TweenLite.to(balk_mc, 1, {x:551 y:balk_mc.y});
i cant get to 1 screen its on a loop i thought that it would be over with the gotoandstop but it doesnt
import flash.events.MouseEvent;
import com.greensock.*;
stop();
button1.addEventListener(MouseEvent.CLICK, button1_clicked);
function button1_clicked(e:MouseEvent):void{
TweenLite.to(balk_mc, 1, {x:141.35, y:balk_mc.y});
gotoAndStop("page1");
}
button2.addEventListener(MouseEvent.CLICK, button2_clicked);
function button2_clicked(e:MouseEvent):void{
TweenLite.to(balk_mc, 1, {x:330.6, y:balk_mc.y});
gotoAndStop("page2");
}
button3.addEventListener(MouseEvent.CLICK, button3_clicked);
function button3_clicked(e:MouseEvent):void{
TweenLite.to(balk_mc, 1, {x:551 y:balk_mc.y});
gotoAndStop("page3");
}
var number:Number = 1;
next_btn.addEventListener(MouseEvent.CLICK, nextImage);
checkNumber();
function nextImage(event:MouseEvent):void {
//trace("next button geklikt!");
number++;
loader.source = "images/tommorrowland"+number+".png";
checkNumber();
}
previous_btn.addEventListener(MouseEvent.CLICK, previousImage);
function previousImage(event:MouseEvent):void {
//trace("previous button geklikt!");
number--;
loader.source = "images/tommorrowland"+number+".png";
checkNumber();
}
function checkNumber():void {
next_btn.visible = true;
previous_btn.visible = true;
if(number == 4){
next_btn.visible = false;
}
if(number == 1){
previous_btn.visible = false;
}
}
}
}
button4.addEventListener(MouseEvent.CLICK, button4_clicked);
function button4_clicked(e:MouseEvent):void{
TweenLite.to(balk_mc, 1, {x:735 y:balk_mc.y});
gotoAndStop("page4");
}
It's clear that you are new to not only Actionscript, but to StackOverflow too. This website isn't designed to help you find your spelling or typing mistakes. Please revise your code before asking a question every time you get an error. Do some research.
This is the last time I or anyone else will help you with this kind of question. You are missing a comma before y.
Change this line:
TweenLite.to(balk_mc, 1, {x:551 y:balk_mc.y});
with this one
TweenLite.to(balk_mc, 1, {x:551, y:balk_mc.y});
And next time read your own code yourself please.

TypeError: Error #1010 in AS3 in accordion

I had created Accordion in flash. and I am getting following error
TypeError: Error #1010: A term is undefined and has no properties.
at accordionSub_fla::accordionMain_1/mouserOver()
But, this error is only reflecting on Panel3, I have 9 Panels, all of them are working fine except Panel3 and this Panel3 is not opening only. Below is the code of function
function mouserOver(e:MouseEvent):void {
var overed:MovieClip = MovieClip(e.target);
for(var i:int=0; i<numChildren; i++)
{
var mc:MovieClip = MovieClip(getChildAt(i));
if(mc.props.ind <= overed.props.ind)
{
TweenLite.to(mc, 1, {x:mc.props.lx, ease:Expo.easeOut});
var request:URLRequest = new URLRequest(mc.props.links);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, urlAction);
function urlAction(evt:TimerEvent)
{
navigateToURL(request, 'myFrame');
}
}
else
{
TweenLite.to(mc, 1, {x:mc.props.rx, ease:Expo.easeOut});
}
}}
Any immediate response will be helpful. Thanks.
Where is numChildren's value come from?
check these lines:
var mc:MovieClip = MovieClip(getChildAt(i));
if(mc.props.ind <= overed.props.ind)
mc can be null in some condition, and access its property will fire an error.
I got an answer.. there is no error on the code. actually when-ever I am clicking on button it gives an error and I made Panel3's heading as button, so it was firing an error. Now, I made it simple text field, now the problem is solved.
anyways, thanks Frank