ActionScript 3.0 - [Error] expecting identifier before 10128 - actionscript-3

So I've been working on a flash game with a friend of mine and we encountered a error that we have been stuck on since yesterday.
The Errors:
Line 5 1084: Syntax error: expecting identifier before 10128
Line 5 1084: Syntax error: expecting identifier before 10129
Line 5 1084: Syntax error: expecting identifier before 10200
Here is the code for the 3 files
10128.as
package
{
import flash.display.*;
public dynamic class 10128 extends MovieClip //Line 5
{
public var back:Object;
}
}
10129.as
package
{
import flash.display.*;
public dynamic class 10129 extends MovieClip //Line 5
{
public var back:MovieClip;
}
}
10200.as
package
{
import flash.display.*;
public dynamic class 10200 extends MovieClip //Line 5
{
}
}
I've looked everywhere and I did view the other posts on this site regarding the same issue but It still didn't work. If anybody knows what's wrong I would appreciate if someone could help me out here.

Class name should start with uppercase character. (updated "must" to "should")
Class name starting with lowercase character might also works, but starting with numeric character doesn't work.
See this link
http://wiki.opensemanticframework.org/index.php/AS3_Coding_Standards
Currently, your class name start with numeric character.
Change your file name and class name, for example...
Test10128.as
package
{
import flash.display.*;
public dynamic class Test10128 extends MovieClip //Line 5
{
public var back:Object;
}
}
Test10129.as
package
{
import flash.display.*;
public dynamic class Test10129 extends MovieClip //Line 5
{
public var back:MovieClip;
}
}
Test10200.as
package
{
import flash.display.*;
public dynamic class Test10200 extends MovieClip //Line 5
{
}
}

Related

AS3 addEventListener not a recognized method in my custom class

I want to have a Class called Commands that I can put different key presses and functions into that will control game states and variables for quick and easy game testing. I'm trying this, but it's not working...
package gameTesting {
import flash.events.KeyboardEvent;
import flash.events.*;
import flash.ui.Keyboard;
import flash.display.*;
import flash.events.EventDispatcher;
public class Commands {
public function Commands() {
addEventListeners();
}
public function addEventListeners():void{
addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
}
public function keyDown(ke:KeyboardEvent):void{
trace("key pressed");
}
}
}
which throws this error:
C:...\Commands.as, Line 15, Column 4 1180: Call to a possibly undefined method addEventListener.
So, I tried having my class extend something that inherits the EventDispatcher methods:
//...
public class Commands extends DisplayObject{
// ...
but I just get this error thrown from my main .as file when trying to instantiate this Class:
ArgumentError: Error #2012: Commands$ class cannot be instantiated.
I also tried throwing the static keyword around just for lols, but no dice.
What am I missing here?
by the way, my reason for doing things this way is just so that I can remove this functionality (so users can't use it) by simply removing the line of code that instantiates this class. I think it's pretty nifty, but if this seems asinine, by all means speak up!
Try to pass stage to Commands,so you can add addEventListener on stage.
import flash.display.Stage;
public class Commands {
public function Commands(stage:Stage) {
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
}
public function keyDown(ke:KeyboardEvent):void{
trace("key pressed");
}
}

How do I fix the error 1120: Access of undefined property?

While sitting, watching and reading about framework, I tried it and cant get my program going.
So when I programmed I had 3 frames. One for pre loader, one for Game (no menu, just straight to game), and one last one for me to keep notes and patch note etc in.
I coded in the frame. I didnt have any extra .as files or nothing, and it all works.
Then I tried converting to having a GameControler.as and a C.as (for constant values etc), and that didn't work.
So I started over, and ended up just trying it out and ended with this code:
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
import flash.utils.*;
import flash.ui.*;
import Game.*;
public class GameController extends MovieClip {
private var score: Number;
public function GameController() {
// constructor code
}
public function startGame() {
score = C.score;
stage.addEventListener(Event.ENTER_FRAME, update);
}
public function scoreF(e: MouseEvent):void {
score = score + 1;
}
hitBtn.addEventListener(MouseEvent.CLICK, scoreF)
private function update(e: Event) {
score_n.text = String(score);
}
}
}
I end up with these two errors.
Line 30, Column 3 1120: Access of undefined property hitBtn.
Line 30, Column 45 1120: Access of undefined property scoreF.
What am I not understanding?
I just wanna click the button, witch is on stage, add up the score and update the on stage score.
Even though your question was answered, here is a pattern you might want to follow:
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
import flash.utils.*;
import flash.ui.*;
import Game.*;
public class GameController extends MovieClip {
private var hitBtn:MovieClip;
private var score: Number;
public function GameController() {
// constructor code
createChildren();
}
protected function createChildren():void {
// when it was not read from the display list
// or created in a subclass via inheritence
if (!hitBtn) {
hitBtn = getChildByName('hitBtn') as MovieClip;
if (hitBtn) {
hitBtn.addEventListener(MouseEvent.CLICK, scoreF);
} else {
trace('Child #hitBtn is not found or not a MovieClip.').
}
}
}
public function startGame() {
score = C.score;
if (stage) {
stage.addEventListener(Event.ENTER_FRAME, update);
} else {
trace("Attempt to start the game, although the controller is not added to stage.");
}
}
public function scoreF(e: MouseEvent):void {
score = score + 1;
}
private function update(e: Event) {
score_n.text = String(score);
}
}
}
When using Flash to add children, those are added to the MovieClip when it is created, so you can access them right away. Following the pattern will give you more safety when working on larger projects, which sometimes change ... this way you can get very fast an idea of what's wrong.

timer not working in class actionscript 3

package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
public class MasterContainer extends MovieClip
{
public var playTimer:Timer = new Timer(1000,16);
public function MasterContainer()
{
// constructor code
t1.setSoundName("drum.mp3");
t2.setSoundName("pluck.mp3");
t3.setSoundName("drum.mp3");
t4.setSoundName("drum.mp3");
t5.setSoundName("drum.mp3");
t6.setSoundName("drum.mp3");
t7.setSoundName("drum.mp3");
t8.setSoundName("drum.mp3");
masterPlay.addEventListener(flash.events.MouseEvent.CLICK, handleMasterPlay);
playTimer.addEventListener(TimerEvent.TIMER, onTick);
}
public function onTick(event:TimerEvent):void
{
t1.playSound();
t2.playSound();
t3.playSound();
t4.playSound();
t5.playSound();
t6.playSound();
t7.playSound();
t8.playSound();
}
private function handleMasterPlay(e:MouseEvent):void
{
trace('bla');
}
}
}
this a chopped version of my class. the error i am getting is:
C:\Users\Mark\Documents\Creative Multimedia\semester 5\Action Script\project\MasterContainer.as, Line 9 1046: Type was not found or was not a compile-time constant: Timer.
C:\Users\Mark\Documents\Creative Multimedia\semester 5\Action Script\project\MasterContainer.as, Line 9 1180: Call to a possibly undefined method Timer.
C:\Users\Mark\Documents\Creative Multimedia\semester 5\Action Script\project\MasterContainer.as, Line 9 1180: Call to a possibly undefined method Timer.
i dont understand this error any help would be appreciated.
import flash.utils.Timer;
Did you miss this?
All errors indicates that the Timer class can't be found - check your import statement it should contain this: import flash.utils.Timer;

Error accessing a packaged class, 1046: Type was not found or was not a compile-time constant

I know this question has been asked countless times on SO, but mine is just weird.
I have a package called critters for the characters in my game.
Of all the classes in this package, one (ACustomSocket) encountered 1046 error when I declare it in my code. Dog is in the same package but does not get the error.
package{
import critters.*;
// all necessary imports follow
public class GameGUI extends MovieClip {
...
private var socket:ACustomSocket;
private var dog:Dog;
...
}
}
Why is there such a difference?
Here's how ACustomSocket is declared.
package critters {
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
class ACustomSocket extends Socket {
private var response:String;
public function ACustomSocket(host:String = null, port:uint = 0) {
....
}
}
}
And here Dog.
package critters {
import flash.display.MovieClip;
public class Dog extends MovieClip {
// Initialization:
public function Dog() {
...
}
}
}
Well make your class ACustomSocket Public so other package can use it :
public class ACustomSocket extends Socket {...}

How to pass arguments to stage instances in ActionScript 3?

I have an instance on my stage that I dragged from my library at design time. This instance links to a custom class who's constructor takes an argument.
package
{
import flash.display.MovieClip;
import flash.media.Sound;
public class PianoKey extends MovieClip
{
var note:Sound;
public function PianoKey(note:Sound)
{
this.note = note;
}
}
}
Obviously, trying to run the the code as is yields the following argument count error:
ArgumentError: Error #1063: Argument
count mismatch on PianoKey(). Expected
1, got 0.
Is there any way to set arguments on an instance that has been manually dragged to the stage?
This may help you. Just little changes are required in Custom Class
package
{
import flash.display.MovieClip;
import flash.media.Sound;
public class PianoKey extends MovieClip
{
var note:Sound;
public function PianoKey(note:Sound=null)
{
if(note!=null)
{
this.note = note;
}
}
}
}
I think the only way to do this is by making a PianoKey component. This will have component properties that can be set. They're a real pain to set up though.
Why not use a setter instead?
package
{
import flash.display.MovieClip;
import flash.media.Sound;
public class PianoKey extends MovieClip
{
var _note:Sound;
public function PianoKey()
{
}
public function set note(value:Sound)
{
this._note = value;
}
}
}