Flash CS6 error: 1084 - actionscript-3

On flash CS6 Actionscript 3.0, I am getting this error code.
Scene 1, Layer 'good guy', Frame 1, Line 23 1084: Syntax error: expecting identifier before assign.
What is this error? I do not understand.
Here is my code.
`import flash.events.MouseEvent;
var mouseIsDown = false;
stage.addEventListener(MouseEvent.MOUSE_DOWN, clicked);
stage.addEventListener(MouseEvent.MOUSE_UP, unclicked);
function clicked (n:MouseEvent)
{
mouseIsDown = true;
}
function unclicked (n:MouseEvent)
{
mouseIsDown = false;
}
addEventListener(Event.ENTER_FRAME, mainLoop);
function mainLoop (e:Event)
{
if (mouseIsDown)
{
gg_mc.y -= 10
}
else
{
gg_mc.y +
= 10
}
for (var I = 0; I < numChildren; I++)
{
if (getChildAt(I) is bad)
{
var b = getChildAt(I) as bad;
if (b.hitTestObject(gg_mc))
{
trace ("You got hit! GAME OVER")
}
}
}
}

That error means you have a formatting error in your code.
This line:
gg_mc.y +
= 10
There should be no line break or space there
gg_mc.y += 10;
Also,
`import flash.events.MouseEvent;
That quote at the start is invalid, take it out.

Related

"TypeError: Error #1009: Cannot access a property or method of a null object reference" while using gotoAndplay function

I was trying to add a gameover screen with a restart button for my game.I had placed the restart button at frame 22.When my player dies it goes to frame 22 and i'm able to restart the game on clicking the button,but this message gets looped in the output area.Please help me how i can correct this issue.
Issue is not there when i remove the line
gotoAndPlay(22);
at Frame 17,but without that i will not get the desired functionality.
Please find my code below
At Frame 17 - Game code
stop();
import flash.events.Event;
import flash.events.MouseEvent;
var mouseIsDown = false;
var speed = 0;
var score = 0;
addEventListener(Event.ENTER_FRAME,mainLoop);
stage.addEventListener(MouseEvent.MOUSE_DOWN,clicked);
stage.addEventListener(MouseEvent.MOUSE_UP,unclicked);
function clicked(m:MouseEvent)
{
mouseIsDown = true;
}
function unclicked(m:MouseEvent)
{
mouseIsDown = false;
}
function mainLoop(e:Event)
{
score = score + 10;
output.text = "Score: "+score;
if(mouseIsDown)
{
speed -= 2;
}
else
{
speed+=2;
}
if(speed > 10) speed = 10;
if(speed < -10) speed = -10;
player.y += speed;
for(var i = 0; i < numChildren; i++)
{
if (getChildAt(i) is Cloud || getChildAt(i) is Boundary)
{
var b = getChildAt(i) as MovieClip;
if(b.hitTestObject(player))
{
for(var counter = 0; counter < 12; counter++)
{
var boom = new Boom();
boom.x = player.x;
boom.y = player.y;
boom.rotation = Math.random() * 360;
boom.scaleX = boom.scaleY = 0.5 + Math.random();
addChild(boom);
}
player.visible = false;
removeEventListener(Event.ENTER_FRAME,mainLoop);
gotoAndPlay(22);
}
}
}
}
At frame 22 - Restart screen
stop();
import flash.events.MouseEvent;
foutput.text = "Score: "+ fscore;
btn_playagain.addEventListener(MouseEvent.CLICK, playagain);
function playagain(m:MouseEvent)
{
gotoAndPlay(17);
}
btnback3.addEventListener(MouseEvent.CLICK, backMain3);
function backMain3(m:MouseEvent)
{
gotoAndPlay(1);
}
At frame 1 - Main Menu screen
stop();
import flash.events.MouseEvent;
import flash.system.fscommand;
btnnewgame.addEventListener(MouseEvent.CLICK, newGame);
function newGame(m:MouseEvent)
{
gotoAndPlay(17);
}
btnins.addEventListener(MouseEvent.CLICK, instruct);
function instruct(m:MouseEvent)
{
gotoAndPlay(6);
}
btncredits.addEventListener(MouseEvent.CLICK, credits);
function credits(m:MouseEvent)
{
gotoAndPlay(11);
}
btnexit.addEventListener(MouseEvent.CLICK, exitfunc);
function exitfunc(m:MouseEvent)
{
fscommand("quit");
}
At Frame 6 - Instructions Screen
stop();
btnback1.addEventListener(MouseEvent.CLICK, backMain1);
function backMain1(m:MouseEvent)
{
gotoAndPlay(1);
}
At Frame 11 - Credits Screen
stop();
btnback2.addEventListener(MouseEvent.CLICK, backMain2);
function backMain2(m:MouseEvent)
{
gotoAndPlay(1);
}
That error means that you are trying to call a method on a null object, meaning one of the objects you are using on frame 22 doesn't actually exist at that moment.
The likely candidates for the offending variable are foutput, btn_playagain, and btnback3. Check to make sure that they are on the stage at frame 22, and are spelt correctly.
You use output.text on frame 17, are you sure that it should be foutput.text on frame 22?

Error #2025: The supplied DisplayObject must be a child of the caller - Game Looping when after gotoAndStop

So ok Im somewhat new to flash im more of a java man myself but anyway I keep getting this error and all the solutions ive been find either don't work or they break the games collision
Here's the Code
stop();
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
import flash.events.Event;
import flash.events.TimerEvent;
var playerobj:player;
var nextObject:Timer;
var objects:Array = new Array();
var score:int = 0;
const speed:Number = 9.0;
playerobj = new player();
playerobj.y = 650;
addChild(playerobj);
setNextObject();
addEventListener(Event.ENTER_FRAME, moveObjects);
function setNextObject()
{
nextObject = new Timer(1000+Math.random()*1000,1);
nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
nextObject.start();
}
function newObject(e:Event)
{
var newObject:AI;
newObject = new AI();
newObject.x = Math.random() * 480;
addChild(newObject);
objects.push(newObject);
setNextObject();
}
function moveObjects(e:Event)
{
for (var i:int=objects.length-1; i>=0; i--)
{
objects[i].y += speed;
if (objects[i].y > 800)
{
removeChild(objects[i]);
score = score + 10000;
objects.splice(i,1);
}
if (objects[i].hitTestObject(playerobj))
{
cleanUp();
}
}
playerobj.x = mouseX;
}
function cleanUp():void
{
while (this.numChildren > 0)
{
removeChildAt(0);
}
nextObject.stop();
gotoAndStop(4);
stop();
}
It must be somehow related to this problem but whenever gotoAndStop is called the game seems to loop around back into the frame not really sure why, Thanks for your help
In the cleanup function, right after declaring it, you should remove the ENTER_FRAME event listener. Also, I would stop the timer before removing childs and I would just remove the objects you added to stage dynamically. And the stop() in the cleanup function is redundant.
function cleanUp():void {
removeEventListener(Event.ENTER_FRAME, moveObjects);
nextObject.stop();
for(var i:uint = 0; i < objects.length; i++){
removeChild(objects[i]);
}
removeChild(playerObj)
gotoAndStop(4);
}
Also, it's better to keep minimal code in the timeline and move as much as you can in classes.
the error is in the cleanUp()
function moveObjects(e:Event)
{
for (var i:int=objects.length-1; i>=0; i--)
{
objects[i].y += speed;
if (objects[i].y > 800)
{
removeChild(objects[i]);
score = score + 10000;
objects.splice(i,1);
}
if (objects[i].hitTestObject(playerobj))
{
cleanUp();
}
}
//playerobj no more exists if cleanUp() is called, move this line above cleanUp();
//playerobj.x = mouseX;
//or inside cleanUp() put that line
//removeEventListener(Event.ENTER_FRAME, moveObjects);
}

ActionScript 3.0: Error #1034: Type Coercion failed: cannot convert displayObject$ to DefaultPackage at CutomeClass()

I'm a student I have a final project want to deliver it after two days.
I'm making a drag and drop game, I watched a tutorial to do that.
But after ending coding I faced a weird error!
I've I checked that my code is the same as the code in the tutorial.
This is the Debug error report:
Attempting to launch and connect to Player using URL E:\FL\ActionScript\Drag and Drop Project\DragAndDrop.swf
[SWF] E:\FL\ActionScript\Drag and Drop Project\DragAndDrop.swf - 87403 bytes after decompression
TypeError: Error #1034: Type Coercion failed: cannot convert paper1$ to DragDrop.
at Targets()[E:\FL\ActionScript\Drag and Drop Project\Targets.as:23]
My .fla File is containing 12 Objects to drag and another 12 Objects to drop on it.
The idea here is when drop the Object on the target the Object will become invisible and the target become visible (in .fla file target alpha = 0).
I made two classes:
DragDrop.as : for the objects that I'm going to drag.
Targets.as : for the targets that I'm going to drop Objects on it.
Note: match function is to animate "GameOver" MovieClip When completing the game.
DragDrop.as:
package
{
import flash.display.*;
import flash.events.*;
public class DragDrop extends Sprite
{
var origX:Number;
var origY:Number;
var target:DisplayObject;
public function DragDrop()
{
// constructor code
origX = x;
origY = y;
addEventListener(MouseEvent.MOUSE_DOWN, drag);
buttonMode = true;
}
function drag(evt:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
startDrag();
parent.addChild(this);
}
function drop(evt:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, drop);
stopDrag();
if(hitTestObject(target))
{
visible = false;
target.alpha = 1;
Object(parent).match();
}
x = origX;
y = origY;
}
}
}
Targets.as:
package
{
import flash.display.*;
import flash.events.*;
public class Targets extends MovieClip
{
var dragdrops:Array;
var numOfMatches:uint = 0;
var speed:Number = 25;
public function Targets()
{
// constructor code
dragdrops = [paper1,paper2,paper3,paper4,paper5,paper6,
paper7,paper8,paper9,paper10,paper11,paper12,];
var currentObject:DragDrop;
for(var i:uint = 0; i < dragdrops.length; i++)
{
currentObject = dragdrops[i];
currentObject.target = getChildByName(currentObject.name + "_target");
}
}
public function match():void
{
numOfMatches++;
if(numOfMatches == dragdrops.length)
{
win.addEventListener(Event.ENTER_FRAME, winGame);
}
}
function winGame(event:Event):void
{
win.y -= speed;
if(win.y <= 0)
{
win.y = 0;
win.removeEventListener(Event.ENTER_FRAME, winGame);
win.addEventListener(MouseEvent.CLICK, clickWin);
}
}
function clickWin(event:MouseEvent):void
{
win.removeEventListener(MouseEvent.CLICK, clickWin);
win.addEventListener(Event.ENTER_FRAME, animateDown);
var currentObject:DragDrop;
for(var i:uint = 0; i < dragdrops.length; i++)
{
currentObject = dragdrops[i];
getChildByName(currentObject.name + "_target").alpha = 0;
currentObject.visible = true;
}
numOfMatches = 0;
addChild(win);
}
function animateDown(event:Event):void
{
win.y += speed;
if(win.y >= stage.stageHeight)
{
win.y = stage.stageHeight;
win.removeEventListener(Event.ENTER_FRAME, animateDown);
}
}
}
}
...Thanks
Are you sure what you're putting into array in Target instance's array IS DragDrop instances?
dragdrops = [paper1,paper2,paper3,paper4,paper5,paper6,
paper7,paper8,paper9,paper10,paper11,paper12,];
I don't see any definitions for "paper1" in the code. And your error is telling paper1 is not a DragDrop instance.

Strange issue with preloader

I have some problem with my preloader.
Preloader Code:
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
var game:MovieClip
var added:Boolean;
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("source.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
function onCompleteHandler(e:Event):void {
game = e.currentTarget.content
game.alpha = 0;
}
function onProgressHandler(e:ProgressEvent):void {
loader.loadBar.setProgress(e.bytesLoaded, e.bytesTotal);
}
addEventListener(Event.ENTER_FRAME, function(e:Event):void {
if(game != null){
if(!added) {
addChild(game);
added = true;
}
if(game.alpha < 1) game.alpha += 0.1;
When I load my game console returns TypeError: Error #1009: Cannot access a property or method of a null object reference.
I turn on permit debugging in game and again load. Now console returns TypeError: Error #1009: Cannot access a property or method of a null object reference.
at main()[C: \Users\Lukasz\Desktop\Flash\rs\main.as:141];
So I checked 141 line and since 141 to 155 I have keyboard events.
stage.addEventListener(KeyboardEvent.KEY_UP, function(e:KeyboardEvent):void {
if(e.keyCode == 32 && moveAvailable) {
startEvent();
}else if(e.keyCode == 32) {
moveAvailable = true;
}
moveSpeed = 70;
});
stage.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent):void {
if(e.keyCode == 32) {
moveSpeed = 140
if(!startBtn.enb) moveAvailable = false;
}
});
When I get comment /**/ between this code game load correctly.
By the way I try this.parent and parent. instead of stage. but nothing changed :(
Someone have idea on this problem ?
You need check stage before use it
if (stage) {
addStageEvent();
} else {
this.addEventListener(Event.ADDED_TO_STAGE, addStageEvent);
}
function addStageEvent(e:Event = null):void {
//put the 141-155 line code here
}

Flash action script tweenlite 1084

I'm a beginner in flash i got an error in actions script 3.0
I'm using tween lite
I got the error 1084: Syntax error: expecting colon before comma.
its about this line
TweenLite.to(balk_mc, 1, {x:141,35, y:balk_mc.y});
And it says line 10 and 16
The whole code im using is:
import flash.events.MouseEvent;
import com.greensock.*;
stop();
button1.addEventListener(MouseEvent.CLICK, button1_clicked);
function button1_clicked(e:MouseEvent):void{
gotoAndStop("page1");
TweenLite.to(balk_mc, 1, {x:141,35, y:balk_mc.y});
}
button2.addEventListener(MouseEvent.CLICK, button2_clicked);
function button2_clicked(e:MouseEvent):void{
gotoAndStop("page2");
TweenLite.to(balk_mc, 1, {x:330,6, y:balk_mc.y});
}
button3.addEventListener(MouseEvent.CLICK, button3_clicked);
function button3_clicked(e:MouseEvent):void{
gotoAndStop("page3");
TweenLite.to(balk_mc, 1, {x:551, y:balk_mc.y});
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{
gotoAndStop("page4");
TweenLite.to(balk_mc, 1, {x:551, y:balk_mc.y});
}
You have written 141,35 instead of 141.35. It's a typing error. Numbers in coding languages are written with a point. Same goes to 330,6 you've got in your code.