Alright, alright. I took a vacation, kill me.
Nah actually im coming to realize the term burnt out is really a verb not a suggestion. Im tired, basically too much work and school. Blah, im done, i finish. haha nah, lets get back to work.
So if you ready the reading for the Midterm in authoring, it explains that the requests are to be made using a Super Class. That combines all the little glamorous things that can be accomplished using the Draw Shape function from the Sprite class.
Well Lets get started, the assigment wants you to draw
1 green circle
1 grey square
1 blue square
and
1 red ellipse
Luckily since we will be accomplishing this all from one class, we dont have to hard code any of these shapes using the draw function. We can put that all into our class.
Lets start by creating a class called
DrawShape
with the hierchy placed in a com folder, in an ai folder. blah blah. yes we know that,
But do you know why we do that?
The reason you imbed your custom classes in deep rooted folders with the names of your company, is to insure your class. If people steal your code, there gonna have to work realy hard to get your company name out of the hierchy. Get it?
Next the class we created has to be a super class extending sprite!
This looks like
public class DrawShape extends Sprite{
Next we are going to create two custom classes, First lets build our circle function.
In our circle function we want to define some perameters
public function drawCircles(
name:String,
fillColor:uint,
strokeWeight:uint,
strokeColor:uint,
xPos:uint,
yPos:uint,
radius:uint)
:void{
Look at all those definitions! Basicaly I wrote out all that I want to be able to assign when building this shape. Next I need to associate my custom properties to variables within the sprite class. So with in my function I start with the fillColor
graphics.beginFill(fillColor)
This is done in the graphics class.
graphics.lineStyle(strokeWeight, strokeColor)
graphics.drawCircle(xPos, yPos, radius);
}
These are all defined in my Function
Looks like this!
public function drawCircles(name:String, fillColor:uint, strokeWeight:uint, strokeColor:uint, xPos:uint, yPos:uint, radius:uint):void{
graphics.beginFill(fillColor)
graphics.lineStyle(strokeWeight, strokeColor)
graphics.drawCircle(xPos, yPos, radius);
}
So now when you call up a drawCircles function you define all your properties!
I create a variable for greenCircle, it is of our DrawShape class and is a New DrawShape
private var greenCircle:DrawShape = new DrawShape;
So then we say what our greenCircle is:
greenCircle.drawCircles("greenCircle", 0x66CC33, 7, 0x336600, 50, 100, 50);
addChild(greenCircle);
//Notice it is in our drawCircles function within our DrawShape class!
See how it works!
See if you can get it to work and draw your other shapes!
The same process is used in the drawRectangle and drawElipse function within our DrawShape class!
NEXT....
I add some listeners to my new shapes!
greenCircle.addEventListener(MouseEvent.CLICK, greenCircleRemover);
redEllipse.addEventListener(MouseEvent.CLICK, greyRecRemove);
blueRectangle.addEventListener(MouseEvent.CLICK, addGreenCirc);
miniGreenCircle.addEventListener(MouseEvent.CLICK, moveUp);
First function:
function greenCircleRemover(e:Event):void{
removeChild(greenCircle);
}
This will remove the child of greenCircle var!
Get it?
The next one is exactly the same! but you remove the grey rectangle!
Now we say if you cclick our blue rectangle we want to add 10 green circles!
well within our blueRect function we need a for loop that runs 10 times.
Within that loop we want to build a green circle every time it loops.
Lets create the first green circle in a var!
Then we can define what our miniGreenCircle variables is!
miniGreenCircle.drawCircles("miniGreenCircle", 0x66CC33, 2, 0x336600, i * 25, 275, 10);
Then we want to addChild.
Bling that it!
We also want to move those up 10 pixels when they are clicked. Since they are all the instance of
miniGreenCircle, all we need is one function to control that variable!
Then we -= 10 to the y position!
Get that?
Let me know if you got it! COMMENT!
:D
This should add the 10 green circles
Monday, August 18, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment