PDA

View Full Version : [AS3] Package Import Not Working?


SmurfMX
06-28-2006, 09:46 PM
I've been playing with AS3 and I just can't get my package to import into my fla. My folder structure is as follows.

|Fireworks
|--|classes
|--|--Fireworks.as
|--fireworkApp.fla
|--fireworkApp.swf

As far as I know the code below, which is inside my FLA should work.

import classes.Fireworks.*;

var userInput:UInput = new UInput();

The package is as follows:

package classes.Fireworks{

import flash.event.*;
import flash.display.Sprite;
import flash.geom.Point;

public class UInput extends Sprite{

public function UInput(Void){
trace("UI Initalized");
addListener(MouseEvent.MOUSE_DOWN, makeFirework);
}

private function makeFirework(evt:MouseEvent):Void{
addChild(new Firework(Math.random()*100));
}
}

class Firework extends Sprite{

private var pNum:Number;

public function Firework($numParticles:uint){

pNum = $numParticles;
init();
}

private function init(Void):Void{

for(var i:Number = 0; i < pNum; i++){

var vector:Point = new Point(Math.random()*3, Math.random()*3);
addChild(new Particle(Math.random()*3, vector));
}
}

}

class Particle extends Sprite{

public function Particle($radius:uint){

var circle:Shape = new Shape();
circle.graphics.lineStyle( 2, 0xFF0000);
circle.graphics.beginFill( 0x0000FF, 100);

circle.graphics.drawCircle($radius);

addChild(circle);
}
}
}

Any help would be greatly appreciated :).

senocular
06-29-2006, 12:10 AM
You have a lot of things going on there. To point out a few:

- Void should be void (lowercase v) and is not used as a function parameter if it accepts no parameters
- you can have only one class defined for any package block in a given AS file
- flash.event.* should be flash.events.*
- instead of using var userInput:UInput = new UInput(); in the first frame, set UInput as the Document class in the property inspector

Be sure to check out the docs and migration guide etc. They'll help guide you in the right direction. It will just take some commitment to get through the reading.

SmurfMX
06-29-2006, 12:43 AM
Thanks senocular, I did everything you said, broke it up into three AS files (I misunderstood what package really was) and added UInput as my document class. However when I test the movie I get a weird error.

Error: Error #2136: The SWF file file:///D|/Sam/Flash%209/fireworks/fireworksApp.swf contains invalid data.
at UInput/::frame1()

That only occurs when I have the new UInput() code in my first frame.

rahul_7star
12-11-2007, 12:17 AM
HI
i m getting 1 eeror as packeage cannot be nested , the code is






package s {
import flash.display.Sprite;
import flash.text.TextField;
public class Suplemental_1 extends Sprite
{
private var tField:TextField;
public function Suplemental_1 ()
}
public function thisTest ():void
{
tField = new TextField();
tField.autoSize = "left";
tField.background = true;
tField.border = true;
tField.x = 200;
tField.y = 200;
tField.text = "Hello You, what is your name?";
addChild(tField);
}
}







i had cretaded 1 folder name as "s" and place d fla inside it


ANY HELP

Felixz
12-11-2007, 05:40 PM
Every class must have separate *.as unless its a helper class which is visible in the same *.as file and can't see external classes