Copy link to clipboard
Copied
I have a code inside of an actionscript file, and i receive multiple errors when attempting to debug:
1120: Access of undefined property square.
1180: Call to a possibly undefined method addChild.
1120: Access of undefined property square.
1120: Access of undefined property square.
1120: Access of undefined property fl_click.
1120: Access of undefined property myTimer.
1120: Access of undefined property timerListener.
1120: Access of undefined property myTimer.
Here is my code for my main actionscript file:
package
{
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Game extends MovieClip
{
public var myTimer:Timer = new Timer(50);
public var square:Square;
square.addEventListener(MouseEvent.CLICK, fl_click);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
myTimer.start();
private function timerListener(e:TimerEvent):void
{
square.edgeCorrect;
}
private function fl_click(event:MouseEvent):void
{
square.moveDownABit();
}
public function Game();
{
square = new Square();
addChild( square );
}
I am a beginner, so please tell me specifically what to do with my code, thanks!
The big problem is this line:
public function Game();
Remove semicolon and try to compile again.
Copy link to clipboard
Copied
is Game your document class?
if yes, you need something like:
package { import flash.events.MouseEvent; import flash.display.MovieClip; import flash.utils.Timer; import flash.events.TimerEvent; public class Game extends MovieClip { public var myTimer:Timer; public var square:Square;
public function Game();
private function timerListener(e:TimerEvent):void {
{
square = new Square();
addChild( square );square.addEventListener(MouseEvent.CLICK, fl_click);
myTimer= new Timer(50);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
myTimer.start();
}
// this doesn't do anything useful
square.edgeCorrect; } private function fl_click(event:MouseEvent):void { square.moveDownABit(); }
Copy link to clipboard
Copied
No I still have all of the same errors . And yes, Game is my document class, i have had this problem for 3 days . Square is just a picture of a square in my library, i just have a blank stage, the game.as with the code you gave me above, and Square.as which has this code:
package
{
import flash.display.MovieClip;
public class Square extends MovieClip
{
var score:Number = 0;
var square_x:Number;
var square_y:Number;
public function Square()
{
height = Math.round(Math.random() * 160 + 50);
width = height;
square_x = Math.round(Math.random() * 385 + (width / 2));
square_y = Math.round(Math.random() * 700 + (height / 2));
x = square_x;
y = square_y;
trace("X:" + x, "Y:" + y, "Height and Width:" + height);
}
public function moveDownABit():void
{
trace("Object Clicked");
height = Math.round(Math.random() * 160 + 50);
width = height;
square_x = Math.round(Math.random() * 480 + (width / 2));
square_y = Math.round(Math.random() * 750 + (height / 2));
if (x + (width/2) > 480)
{
x = x - 10;
}
if (y + (height/2) >700)
{
y = y - 10;
}
x = square_x;
y = square_y;
score = score + 1;
trace(score);
}
public function edgeCorrect():void
{
if (x + (width/2) > 480)
{
x = x - 10;
}
if (y + (height/2) >700)
{
y = y - 10;
}
}
}
}
Copy link to clipboard
Copied
does your library symbol have class, Square?
Copy link to clipboard
Copied
Idk what you mean, but the AS linkage of my Square is to Square
Copy link to clipboard
Copied
Would it help if I were to upload my files? All it is is the Square.as , Game.as, blank stage, and the Square library picture...
Copy link to clipboard
Copied
in your fla, click file>publish settings>swf>tick 'permit debugging'. retest.
copy and paste the complete error message.
copy and paste your corrected document class.
bold the line number mentioned at the top of the error message.
Copy link to clipboard
Copied
This is air for android, but that shouldn't matter, they were already ticked.
Game.as(the code you corrected for me) document class linked to FLA file in properties:
package
{
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Game extends MovieClip
{
public var myTimer:Timer = new Timer(50);
public var square:Square;
public function Game();
{
square = new Square();
addChild( square );
square.addEventListener(MouseEvent.CLICK, fl_click);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
myTimer.start();
};
private function timerListener(e:TimerEvent):void
{
square.edgeCorrect;
}
private function fl_click(event:MouseEvent):void
{
square.moveDownABit();
}
}
}
Square.as, linked by AS linkage to Square in library:
package
{
import flash.display.MovieClip;
public class Square extends MovieClip
{
var score:Number = 0;
var square_x:Number;
var square_y:Number;
public function Square()
{
height = Math.round(Math.random() * 160 + 50);
width = height;
square_x = Math.round(Math.random() * 385 + (width / 2));
square_y = Math.round(Math.random() * 700 + (height / 2));
x = square_x;
y = square_y;
trace("X:" + x, "Y:" + y, "Height and Width:" + height);
}
public function moveDownABit():void
{
trace("Object Clicked");
height = Math.round(Math.random() * 160 + 50);
width = height;
square_x = Math.round(Math.random() * 480 + (width / 2));
square_y = Math.round(Math.random() * 750 + (height / 2));
if (x + (width/2) > 480)
{
x = x - 10;
}
if (y + (height/2) >700)
{
y = y - 10;
}
x = square_x;
y = square_y;
score = score + 1;
trace(score);
}
public function edgeCorrect():void
{
if (x + (width/2) > 480)
{
x = x - 10;
}
if (y + (height/2) >700)
{
y = y - 10;
}
}
}
}
Errors:
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 15 | 1120: Access of undefined property square. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 16 | 1180: Call to a possibly undefined method addChild. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 16 | 1120: Access of undefined property square. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 18 | 1120: Access of undefined property square. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 18 | 1120: Access of undefined property fl_click. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 19 | 1120: Access of undefined property myTimer. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 19 | 1120: Access of undefined property timerListener. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 20 | 1120: Access of undefined property myTimer. |
Message was edited by: AngryGamerProductions
Copy link to clipboard
Copied
create a new directory.
save your fla and both those class files into the new directory.
retest.
p.s.
private function timerListener(e:TimerEvent):void
{
square.edgeCorrect;
}
should be
private function timerListener(e:TimerEvent):void
{
square.edgeCorrect();
}
Copy link to clipboard
Copied
I changed the directory and the code that you changed above, but no luck, the errors now just are the same, but with a different directory now. I have one question, under publish settings --> Script "Actionscript 3.0" --> Settings of the script, all of the 3 boxes are checked, but underneath in the source path, i have one that says "./classes/". Is that correct? After all i have tried, thats the only thing i can think of.
I unchecked strict mode, but the file size increase 45000% and my system is shutting down, it crashed a system file.
Copy link to clipboard
Copied
source path should be "." only.
Copy link to clipboard
Copied
I changed it to that, same errors.
Copy link to clipboard
Copied
copy and paste the error messages.
Copy link to clipboard
Copied
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 15 | 1120: Access of undefined property square. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 16 | 1180: Call to a possibly undefined method addChild. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 16 | 1120: Access of undefined property square. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 18 | 1120: Access of undefined property square. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 18 | 1120: Access of undefined property fl_click. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 19 | 1120: Access of undefined property myTimer. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 19 | 1120: Access of undefined property timerListener. |
C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 20 | 1120: Access of undefined property myTimer. |
The directory change is that i added a folder: "Color Clicker" inside of "Color Clicker".
Copy link to clipboard
Copied
To all who may be able to help, this is still not solved. 😕
Copy link to clipboard
Copied
On closer inspection, it looks like "call to possibly undefined method addChild means there's a problem compiling at even the lower level. Count your open and close braces and make sure they all match--in the code sample you posted at the top, they don't.
Copy link to clipboard
Copied
I did, i have 5 opening & closing brackets, another person on a different forum said that it looks like the constructor is terminating before it reads the body?
Copy link to clipboard
Copied
The big problem is this line:
public function Game();
Remove semicolon and try to compile again.
Copy link to clipboard
Copied
Thankyou SO MUCH! i have spent 3 days unable to develop my application due to a stray semicolon? I really appreciate your comment, but now i just have one small problem, the width and height of my spawned square is 0, which by my method of calculating the height, is impossible. Here is my method of calculating height and width:
height = Math.round(Math.random() * 160 + 50);
if (height == 0) {height = 50}
width = height;
So in my input, how is it displaying my height and width as 0?
Copy link to clipboard
Copied
This line of code is in constructor - unless there are display objects on display list - dimensions will be 0/0 no matter if you set them or not.
Copy link to clipboard
Copied
How would i fix this? This line of code is in my other AS file btw, here is the full code:
package
{
import flash.display.MovieClip;
public class Square extends MovieClip
{
var score:Number = 0;
var square_x:Number;
var square_y:Number;
public function Square()
{
height = Math.round(Math.random() * 160 + 50);
if (height == 0) {height = 50}
width = height;
square_x = Math.round(Math.random() * 385 + (width / 2));
square_y = Math.round(Math.random() * 700 + (height / 2));
x = square_x;
y = square_y;
trace("X:" + x, "Y:" + y, "Height and Width:" + height);
}
public function moveDownABit():void
{
trace("Object Clicked");
height = Math.round(Math.random() * 160 + 50);
width = height;
square_x = Math.round(Math.random() * 480 + (width / 2));
square_y = Math.round(Math.random() * 750 + (height / 2));
if (x + (width/2) > 480)
{
x = x - 10;
}
if (y + (height/2) >700)
{
y = y - 10;
}
x = square_x;
y = square_y;
score = score + 1;
trace(score);
}
public function edgeCorrect():void
{
if (x + (width/2) > 480)
{
x = x - 10;
}
if (y + (height/2) >700)
{
y = y - 10;
}
}
}
}
This worked just fine before the topic of this question's error came about.
Copy link to clipboard
Copied
Do you have any graphics/objects on Square display list/timeline?
Copy link to clipboard
Copied
Im not sure what you mean by display list, but my stage/timeline are empty, and have not been edited since before, when it actually worked to scale them, i just have Square in my library, which is a square.
Copy link to clipboard
Copied
You need to have something on Square timeline in order to manipulate width/height. If there is nothing on timeline - what is the meaning of width/height? Dimensions of nothing is nothing (zero), right?
Copy link to clipboard
Copied
The reason i have nothing on my timeline, is because i want to spawn that object from my library, are you suggesting that I manually place Square on my stage, and have it be manipulated once the game starts?