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!
1 Correct answer
The big problem is this line:
public function Game();
Remove semicolon and try to compile again.
Copy link to clipboard
Copied
What do you expect to see when instance of Square is spawned?
Copy link to clipboard
Copied
A black square, with a random height, width, and location on the screen, i drew the black square in flash and it is a library file.
The object of this application is for you to click on the square, and it will change locations and dimensions.
Copy link to clipboard
Copied
When you double-click on Square library symbol and Flash opens it - do you see black square there?
Copy link to clipboard
Copied
Nevermind, i accidentaly deleted the square from its own file in the library, i redrew it and it works perfectly. Thx, and cheers!
Copy link to clipboard
Copied
And no, I am not suggesting manual placement of Square on stage. Square is supposed to be some visual, isn't is? In order for it to display any visual - Square itself has to have something on ITS timeline/display list - not main timeline/stage..
Copy link to clipboard
Copied
How do i place itself on its own timeline? Sorry for my confusion, i am new to AS3 and have not worked with timelines before. And yes, it is supposed to be visual.
Copy link to clipboard
Copied
Also, timer handler should be:
private function timerListener(e:TimerEvent):void
{
square.edgeCorrect();
}
Because egdeCorrect is a method - not property.
Copy link to clipboard
Copied
Oh yes i fixed edgeCorrect(), but doesn't addChild put things on my timeline and displaylist?
Copy link to clipboard
Copied
I think you should name your Square Symbol in your library SquareMC, and then when you create the square in the constructor, say
square = new SquareMC();


-
- 1
- 2