So I’m new to AS3 and the whole class thing in general, but I think I have most of it down… maybe. However, I’m plain lost as to what to do with this recent error. I’ve made a class method that draws a shape on the stage. I copied this code and pasted it into a new class I’m working on now that parses RSS feeds, but it doesn’t work in this new class, or at least not how I wanted it to work. I’ve included all the necessary import statements, and I don’t get an error message running the script, it’s just that the shape doesn’t appear. WHY?!
Here’s most of the code I’m using:
package
{
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.display.Graphics;
import flash.display.Stage;
public class myClass extends MovieClip
{
public var mySquare:Sprite;
public var myCircle:Shape = new Shape();
public function myClass():void
{
drawSquare();
}
private function drawSquare():void
{
mySquare = new Sprite();
addChild(mySquare);
mySquare.graphics.beginFill(0x0000FF, 1);
mySquare.graphics.drawRect(0, 0, 100, 100);
mySquare.graphics.endFill();
trace(mySquare.x + " " + mySquare.y); //Outputs '0 0'
}
}
}
Call me crazy, but shouldn’t this work?
##EDIT: Well Im an idiot. I didn’t addchild() the instance of the class on the main timeline. Problem solved.
var test:myClass = new myClass();
addChild(test);