OK, don’t be harsh as this is my first ever code in as3 --and I did it from scratch (I did look up stuff to find out about the ‘event handlers’ and ‘beginfill stuff’).
How would I go about cleaning it up? Making it more dynamic? Easier to edit?
stop()
toolbar.shapeType.text='Rectangle'
var num:int=0
var names:Array=['Rectangle', 'Ellipse', 'Cirlce']
var dragging:Boolean=false
var setVar:Boolean=false
var mc:MovieClip=new MovieClip()
var temp:MovieClip=new MovieClip()
var level:MovieClip=new MovieClip()
var colorTransform:ColorTransform = level.transform.colorTransform;
stage.addChild(level)
var locationX:int
var locationY:int
var location2X:int
var location2Y:int
stage.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);
function mousedown(evt:MouseEvent):void
{
dragging=true
locationX=evt.target.mouseX
locationY=evt.target.mouseY
}
stage.addEventListener(MouseEvent.MOUSE_UP, mouseup);
function mouseup(evt:MouseEvent):void
{
if (dragging==true)
{
dragging=false
level.graphics.beginFill(0x00FFFF);
switch(num){
case 0:
level.graphics.drawRect(locationX, locationY, location2X, location2Y)
break
case 1:
level.graphics.drawEllipse(locationX, locationY, location2X, location2Y)
break
case 2:
level.graphics.drawCircle(locationX, locationY, location2X)
break
}
level.graphics.endFill();
}
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemoved);
function mousemoved(evt:MouseEvent):void
{
if (dragging==true){
if (setVar==true)
stage.removeChild(mc)
{
location2X=evt.target.mouseX-locationX
location2Y=evt.target.mouseY-locationY
mc=new MovieClip();
mc.graphics.beginFill(0x00FFFF, .3);
switch(num){
case 0:
mc.graphics.drawRect(locationX, locationY, location2X, location2Y)
break
case 1:
mc.graphics.drawEllipse(locationX, locationY, location2X, location2Y)
break
case 2:
mc.graphics.drawCircle(locationX, locationY, location2X)
break
}
mc.graphics.endFill();
stage.addChild(mc);
setVar=true
}
}
}
stage.addEventListener(KeyboardEvent.KEY_UP, cancel);
function cancel(evt:KeyboardEvent):void
{
switch(evt.keyCode)
{
case 32:
dragging=false
break
case Keyboard.LEFT:
trace('shapes')
if (num > 0)
{
num-=1
}
toolbar.shapeType=names[num]
break
case Keyboard.RIGHT:
trace('shapes')
if (num<2)
{
num+=1
}
toolbar.shapeType.text=names[num]
break
}
}
/* Mouse Click Event
Clicking on the specified symbol instance executes a function in which you can add your own custom code.
Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the symbol instance is clicked.
*/
button_1.addEventListener(MouseEvent.CLICK, clickPlay);
function clickPlay(event:MouseEvent):void
{
// Start your custom code
// This example code displays the words "Mouse clicked" in the Output panel.
play();
// End your custom code
}
Thanks, in advance! :thumb2:
***
FLA WILL BE UPLOADED IF YOU NEED IT.***