-
As3 Begginner
Hi, Im using Adobe Flash cs6 AS3, I am a complete beginner so bare with me please and I basically need a way to put multiple as3 shapes into one movie, I have 2 classes,
ellipse.as
circle.as
this is my elipse code
package {
import flash.display.MovieClip;
public class Ellipse extends MovieClip {
public function Ellipse(w:Number=145, h:Number=145, r:Number=1500, color:Number=0xFFFF00) {
// constructor code
graphics.beginFill(color);
graphics.drawEllipse(250, 50, 200, 150);
graphics.endFill();
}
}
}
this is my circle code
package {
import flash.display.*;
public class circle extends MovieClip{
public var mc1:MovieClip = new MovieClip();
public function circle() {
// constructor code
mc1.graphics.lineStyle(1);
mc1.graphics.beginFill(6697983);
mc1.graphics.drawCircle(50,50,20);<br />
this.addChild(mc1);mc1.graphics.endFill();
mc1.alpha =.5; mc1.scaleX =2; mc1.scaleY = 3;
}
}
}
there will also eventually be a square, another circle and a rectangle, ive tried various things here.
if I try to put the ellipse and circle in one class, like this
package {
import flash.display.*;
public class circle extends MovieClip{
public var mc1:MovieClip = new MovieClip();
public function circle() {
// constructor code
mc1.graphics.lineStyle(1);
mc1.graphics.beginFill(6697983);
mc1.graphics.drawCircle(50,50,20);<br />
this.addChild(mc1);mc1.graphics.endFill();
mc1.alpha =.5; mc1.scaleX =2; mc1.scaleY = 3;
}
}
}
package {
import flash.display.MovieClip;
public class Ellipse extends MovieClip {
public function Ellipse(w:Number=145, h:Number=145, r:Number=1500, color:Number=0xFFFF00) {
// constructor code
graphics.beginFill(color);
graphics.drawEllipse(250, 50, 200, 150);
graphics.endFill();
}
}
}
/*I get an error saying An ActionScript file can not have more than one externally visible definition: ellipse, circle
If i try to combine the code like this
package
*/{
import flash.display.*;
package {
import flash.display.MovieClip;
public class Ellipse extends MovieClip {
public function Ellipse(w:Number=145, h:Number=145, r:Number=1500, color:Number=0xFFFF00) {
// constructor code
graphics.beginFill(color);
graphics.drawEllipse(250, 50, 200, 150);
graphics.endFill();
public class circle extends MovieClip{
public var mc1:MovieClip = new MovieClip();
public function circle() {
// constructor code
mc1.graphics.lineStyle(1);
mc1.graphics.beginFill(6697983);
mc1.graphics.drawCircle(50,50,20);<br />
this.addChild(mc1);mc1.graphics.endFill();
mc1.alpha =.5; mc1.scaleX =2; mc1.scaleY = 3;
}
}
}
//I get error Packages can not be nested
Ive also got classes can not be nested,
public attributes cant be inside a package from other things ive tried
these codes separate work perfect but i need all of the shapes in one movie, and flash`` will only let me choose one class at a time
thanks in advance for your help.
-
Hello Majic-
I just took a look at your code, and it seems like your classes to work individually. Forgive me for not understanding, but I am failing to understand why you are trying to define two items at once.
You can use several classes within one movie by importing each one, individually... I put this code in the main timeline, but you could easily have this code in an external .as file:
The code below adds both the Circle and Ellipse to the same movie-
Code:
import Ellipse;// this imports your Ellipse Class
import circle;// this imports your circle Class
var myEllipse:Ellipse = new Ellipse();//this creates an Ellipse that you can place on the stage
var myCircle:circle = new circle();//this creates a circle that you can place on the stage
addChild(myEllipse);//this adds the Ellipse to the display list
addChild(myCircle);//this adds the circle to the display list
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|