ActionScript 3, 1084: Syntax error: expecting rightparen before dot - actionscript-3

Can someone help with this please. I'm trying to do a simple coding tutorial and make a guy walk around the screen but I keep running into the same error
Scene 1, Layer 'Actions', Frame 1, Line 11, Column 33 1084: Syntax error:
expecting rightparen before dot.
This is the code and I can't seem to find an explanation for what to do. I've followed the tutorial word by word
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Stage;
heroMc.gotoAndStop("FrontBackStill");
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
function keyDownHandler(keyEvent.KeyboardEvent):void
{
if(keyEvent.keyCode==Keyboard.RIGHT)
{
trace("You pressed right!");
}
}

In the keyDownHandler the parameters should read:
function keyDownHandler(keyEvent:KeyboardEvent):void
{
// ...
}
Noting the colon not a period after the keyEvent.
This is because you're receiving an event object - of which you're naming keyEvent. This is type (:) KeyboardEvent.

Related

Why can't I remove this Movieclip?

I have a TouchEvent function onTouch inside the constructor function of a item_Potion class that gets run when a Movieclip is touched. This function goes through a series of unrelated checks and then in the end it is supposed to remove itself (the Movieclip).
At the end of the onTouch function it is supposed to remove itself by doing the following:this.parent.removeChild(this);
However, this does not work.
I get the following error message:
TypeError: Error #1010: A term is undefined and has no properties.
at Function/item_Potion/$construct/onTouch()[E:\Clients\org\tcdsb\ZenithsReach\item_Potion.as:56]
at runtime::ContentPlayer/simulationSendTouchEvent()
at runtime::SimulatedContentPlayer/clientSocketDataHandler()
The line it's reffering to for the error message (Line 56) has the following:
this.parent.removeChild(this);
My imports:
` import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.*;
import flash.events.TouchEvent;
import flash.net.dns.AAAARecord;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;`
I know the problem is not with the other portions of my code because I have tried switching this line out with visible = false; and I get no errors. Therefore, I am certain that the issue is with the way I am removing the MovieClip, and that is where I need help.
Similiar Sources I have tried that do not work:
How to make a MovieClip remove itself in AS3?
parent is undefined in your example, hence the error "a term is undefined...".
You can avoid the error by wrapping your code in:
if (parent) {
parent.removeChild(this);
}
But based on your comment providing [object global] is sounds like you might actually want something like:
event.currentTarget.parent.removeChild(event.currentTarget);
Which would remove the object that the touch event listener was added to.

Simple Errors in Flash CS6 - ActionScript 3.0

This is probably super simple. I have created a basic replay button in Flash CS6 Pro, ActionScript 3.0. The instance name is correct, but I get a syntax error and '{'expected. What an I doing wrong?
Code:
import flash.events.MouseEvent;
stop();
playAgain_btn.addEventListener(MouseEvent.CLICK, f_playAgain);
function f_playAgain (event:MouseEvent):void
{
gotoAndPlay(1);
}
EDIT:
The errors are as follows:
Scene=Scene 1, layer=actions, frame=1161, Line 1 Syntax Error.
Scene=Scene 1, layer=actions, frame=1161, Line 7 '{' expected.
I believe that removing the space in here:
f_playAgain (event:MouseEvent):void
might do the job
f_playAgain(event:MouseEvent):void

Adding the same function to multiple buttons in Actionscript 3.0

I am trying to add the same button function to 2 different symbols in Flash. One is the logo and the other is text that I converted to a symbol that will show itself during the end scene.
I don't understand what I am doing wrong, but I am extremely new to Actionscript & Flash.
My code looks like this:
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.net.navigateToURL;
import flash.net.URLRequest;
myButton, txtButton.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
function onClick(e:MouseEvent):void{
navigateToURL(new URLRequest("http://www.true.land"), "_blank");
}
But I am getting this error:
Attempting to launch and connect to Player using URL
C:\Users\Angela\Desktop\ASU\GIT 314\Assignment
7\AngelaRogers_Assignment7.swf [SWF] C:\Users\Angela\Desktop\ASU\GIT
314\Assignment 7\AngelaRogers_Assignment7.swf - 351066 bytes after
decompression TypeError: Error #1009: Cannot access a property or
method of a null object reference. at
Button/frame1()[Button::frame1:7]
You must write it twice - once for each button, starting with only it's name: child.addEventListener. There is no shortcut to add the same for two objects at once.
You can write a shortcut function to do this easily enough. (As pointed out by others, your comma is what is causing the error). This I believe is more what you're after: (especially if you keep adding more buttons).
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.net.navigateToURL;
import flash.net.URLRequest;
addClick(myButton, txtButton); //you can add as many items as you want as parameters
function addClick(...buttons):void {
//the ...buttons parameter is known as the '...rest' parameter, and is an array of all the parameters passed to the function
for each(var btn:Sprite in buttons){ //loop through all the items passed in and add the listener
btn.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
}
}
function onClick(e:MouseEvent):void{
navigateToURL(new URLRequest("http://www.true.land"), "_blank");
}

Flash Player 11.2 Video Events addEventListener

Has anyone been able to get an addEventListener working with Flash Player 11.2?
I always get this error:
Scene 1, Layer 'actions', Frame 1, Line 104 1119: Access of possibly
undefined property COMPLETE through a reference with static type
Class.
If I switch my flash player to output to
here is my code:
import flash.events.Event;
import fl.video.VideoEvent;
import fl.video.*;
myVideo.source ="videoName.flv";
myVideo.play();
myVideo.addEventListener(VideoEvent.COMPLETE, vidComplete)
function vidComplete(event:VideoEvent) {
trace("done");
}
For some reason, the AS3 compiler for Flash Player 11 in Flash CS6 seems to ignore the import statements for fl.video.*;
Source: http://forums.adobe.com/message/4699000
This person's solution implies that specifying the entire class package inline in the code as follows should alleviate the issue:
myVideo.source ="videoName.flv";
myVideo.play();
myVideo.addEventListener(fl.video.VideoEvent.COMPLETE, vidComplete)
function vidComplete(event:fl.video.VideoEvent) {
trace("done");
}

flashfirebug As3 console timer or setInterval not working

i have tried to use a timer in the as3 console from FlashFirebug addon but it doesn't work (have tried several combinations). The timer code was this:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
var myTimer = new Timer(1000, 2);
myTimer.addEventListener(TIMER, timerHandler);
myTimer.start();
function timerHandler(event:TimerEvent){trace("timerHandler: ");}
//but it gives this error:
Error #1034: Type Coercion failed: cannot convert r1.deval.rt::FunctionDef#50ef781 to Function.
//also have tried with setInterval with this code:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
import flash.utils.setInterval;
function d(){trace("cc");}
setInterval(d, 2000);
//but console error says:
Error: Call to a possibly undefined method.
//probably need to import something. tried tho import "import flash.utils.setInterval;" but gives this error:"Error: You must import the class before being able to instantiate it. Ex. import flash.display.MovieClip;"
Can you help me on This? timer or setInterval functions?
Thanks,
John
I'm not sure about the error message you're getting, but you do have an error in your code at the point at which you assign the event listener for your timer. You need to access the event name constant from the TimerEvent class like so:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
var myTimer = new Timer(1000, 2);
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.start();
function timerHandler(event:TimerEvent){trace("timerHandler: ");}
There's a decent explanation here on the advantages of using the ActionScript 3.0 Timer class over setInterval.
Well, looks like there is no way to achieve this. FlashFirebug uses D.eval library and I can't find that it supports timers or intervals right now.
I'm not sure you've sorted it yet but it looks like:
var num:int = setInterval(d, 2000);
and if you import import flash.utils.clearInterval; you can stop it like:
clearInterval(num)
The problem is on this line:
myTimer.addEventListener(TIMER, timerHandler);
It should be:
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
// add this ^^^^^^^^^^^
This is quite old. But answering it to help anyone in the future.
FlashFirebug 4.8.0 which is still on the approval queue (at the time of answer) should enable you to inject an SWF file inside the running SWF.
That would allow you to use full AS3 capabilities when you hit limitations with the console.