import classes in flash?

Hussain A

New member
i have the following code:
back = new Sprite();
back.graphics.beginFill(0x000000);
back.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
addChild(bg);

and for each line i have an error 'access of undefined property back' im guessing i need to import a class at the beginning of the file but which one is it? or is there something else im doing wrong?
 
heres the corrected code

var back:Sprite = new Sprite();
back.graphics.beginFill(0x000000);
back.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
addChild(back);

line 1 creates the var back from the class Sprite(), the colon means derived from the class. The bg should be back unless you defien a bg sprite.

the display class is loaded by default in flash otherwise you wouldnt be able to see a stage, but if you did want to load a class it would be

import flash.display. *;

the * means make all methods of the class available. And just to show you how fuss flash is try leaving of the last full stop so teh code reads

import flash.display *;

and you get an error reading that a semi colon is missing, its truly bizarre, but try hat code anyway, just remember that if you instantiate an object from a class you do it with a :
 
Back
Top