// --- art_creator.as --- package { import flash.display.Sprite; import eriks_clases.Button; import eriks_clases.BoxFolder; import eriks_clases.Snake; import eriks_clases.Slider; [SWF(width="310", height="225", frameRate="31")] public class art_creator extends Sprite { // declarations public var box_main:BoxFolder; public var box_about:BoxFolder; public var button1:Button; public var button2:Button; public var button3:Button; public var slider:Slider; public var snake:Snake; // end declarations public function art_creator() { box_main = new BoxFolder(); box_main.Create(5, 5, 300, 200, "ABSTRACT ART CREATOR", "", 0x555588, 1, false); snake = new Snake(); snake.Create(20, 40, 280, 160); box_about = new BoxFolder(); box_about.Create(5, 25, 300, 140, "ABOUT", "\n author: Eriks Kruze \n mail: eriks.kruze@gmail.com \n date: 2009 April. \n\nApplication created with FlashDevelop v3 IDE and Flex3 SDK. This application is something similar with aquarium, when you have nothing to do then you can watch on this snake :)",0x00001d, 0.5, true); button1 = new Button(); button1.Create(15, 175, 40, 20, "play", "pause", snake, 0); button2 = new Button(); button2.Create(65, 175, 40, 20, "clear", "clear", snake, 1); button3 = new Button(); button3.Create(115, 175, 40, 20, "about", "about", box_about, 0); slider = new Slider(); slider.Create(165, 175, 130, 20, snake, 2); this.addChild(box_main); this.addChild(button1); this.addChild(button2); this.addChild(button3); this.addChild(slider); this.addChild(snake); this.addChild(box_about); } } } // --- eriks_clases/BoxFolder.as --- package eriks_clases { import flash.display.Sprite; import flash.events.TextEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; public class BoxFolder extends Sprite { // declaratinons private var box_top:Sprite; private var box_bottom:Sprite; private var box_title:TextField; private var box_text:TextField; // constructor public function BoxFolder() { // intialization } // show or hide folder. Special functon for button interface. public function ButtonAction(value:int):void { if (this.visible == true) this.visible = false; else this.visible = true; } // draw box // color must be in form: 0x0000ff or 255 public function Create(x:int,y:int,width:int,height:int,title:String,text:String,color:int,alpha:Number,button_controled:Boolean):void { var format_text:TextFormat = new TextFormat(); format_text.size = 11; var format_title:TextFormat = new TextFormat(); format_title.size = 12; box_title = new TextField(); box_title.text = title; box_title.autoSize = TextFieldAutoSize.LEFT; box_title.multiline = true; box_title.textColor = 0x9999ff; box_title.text box_title.x = x + 5; box_title.y = y; box_title.setTextFormat(format_title); box_text = new TextField(); box_text.text = text; box_text.autoSize = TextFieldAutoSize.LEFT; box_text.multiline = true; box_text.wordWrap = true; box_text.textColor = 0xccccff; box_text.x = x + 5; box_text.y = y + 10; box_text.width = width -10; box_text.setTextFormat(format_text); box_top = new Sprite(); box_top.graphics.beginFill(color, alpha); box_top.graphics.drawRoundRectComplex(x, y, box_title.length*11, 20, 5,5,0,0); box_top.graphics.endFill(); box_bottom = new Sprite(); box_bottom.graphics.beginFill(color, alpha); box_bottom.graphics.drawRoundRectComplex(x, y+20, width, height-20, 0,10,10,10); box_bottom.graphics.endFill(); addChild(box_top); addChild(box_title); addChild(box_bottom); addChild(box_text); if (button_controled == true) this.visible = false; } } } // --- eriks_clases/Slider.as package eriks_clases { import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.ColorTransform; import flash.text.TextField; public class Slider extends Sprite { private var slider:Sprite; private var slider_x:int; private var slider_y:int; private var slider_width:int; private var slider_height:int; private var slider_color:ColorTransform; private var line:Sprite; // white private var line2:Sprite; // grey (to be wisible if chosen white color) private var button:Sprite; private var button_pressed:Boolean; private var obj:Object; private var obj_value:int; // constructor public function Slider():void { } public function Create(x:int,y:int,width:int,height:int,object:Object,value:int):void { slider_x = x; slider_y = y; slider_width = width; slider_height = height; obj = object; obj_value = value; // man container box of slider slider = new Sprite(); slider.graphics.lineStyle(1, 0xffffff, 0.5); slider.graphics.beginFill(0, 1); slider.graphics.drawRoundRect(slider_x, slider_y, slider_width, slider_height, 20, 20); slider.graphics.endFill(); slider.addEventListener(MouseEvent.CLICK, changeColor); slider.buttonMode = true; slider.useHandCursor = true; slider_color = new ColorTransform(); slider_color.color = 0; slider.transform.colorTransform = slider_color; // line on whitch button slide line = new Sprite(); line.graphics.lineStyle(1, 0xffffff, 0.5); line.graphics.moveTo(slider_x + 10, slider_y + (slider_height/2)); line.graphics.lineTo(slider_x + slider_width - 10, slider_y + (slider_height / 2)); line.addEventListener(MouseEvent.CLICK, changeColor); line.buttonMode = true; line.useHandCursor = true; // grey line (to be wisible if chosen white color) line2 = new Sprite(); line2.graphics.lineStyle(1, 0xcccccc, 0.5); line2.graphics.moveTo(slider_x + 10, slider_y + ((slider_height/2)+1)); line2.graphics.lineTo(slider_x + slider_width - 10, slider_y + ((slider_height / 2)+1)); line2.addEventListener(MouseEvent.CLICK, changeColor); line2.buttonMode = true; line2.useHandCursor = true; // button that when you move changes color button = new Sprite(); button.graphics.lineStyle(1, 0xcccccc, 0.5); button.graphics.beginFill(0xffffff, 1); button.graphics.drawCircle(slider_x + 15, slider_y + (slider_height/2), 5); button.graphics.endFill(); //button.addEventListener(MouseEvent.CLICK, changeColor); button.buttonMode = true; button.useHandCursor = true; this.addChild(slider); this.addChild(line); this.addChild(line2); this.addChild(button); } private function startColorChange(myEvent:MouseEvent):void { button_pressed = true; } private function endColorChange(myEvent:MouseEvent):void { button_pressed = true; } private function changeColor(myEvent:MouseEvent, ... value):void { if (button_pressed == false) { var new_x:int = mouseX; var new_color:int; new_x = int(mouseX); new_x = new_x - (slider_x + 15); if (new_x < 0) new_x = 0; if (new_x > (slider_width - 30)) new_x = slider_width - 30; new_color = int(new_x * (16777215 / (slider_width-30))); // 16777215 dec <-> hex 0xffffff button.x = new_x; slider_color.color = new_color slider.transform.colorTransform = slider_color; obj.ButtonAction(obj_value, new_color); } } } } // --- eriks_clases/Button.as package eriks_clases { import flash.display.Sprite; import flash.events.TextEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.events.MouseEvent; import flash.text.TextFormat; import flash.geom.ColorTransform; public class Button extends Sprite { private var button:Sprite; private var button_text:TextField; private var button_color:ColorTransform; private var position:Boolean; private var title1:String; // title of button when button isn't pressed private var title2:String; // title of button when button is pressed private var obj:Object; private var obj_value:int; // constructor public function Button() { position = false; } // draw button // if you wish that button can control same object then you must have "ButtonAction" funtcion to // this object. public function Create(x:int,y:int,width:int,height:int,text1:String,text2:String,object:Object,object_value:int):void { // saving to golobals title1 = text1; title2 = text2; obj = object; obj_value = object_value; var format_title:TextFormat = new TextFormat(); format_title.size = 12; // add button text button_text = new TextField(); button_text.text = text1; button_text.autoSize = TextFieldAutoSize.LEFT; button_text.multiline = true; button_text.textColor = 0xffffff; button_text.x = x+3; button_text.y = y; button_text.setTextFormat(format_title); // add button rectangle button = new Sprite(); button.graphics.lineStyle(0,0xff0000,0.5); button.graphics.beginFill(0xff0000, 0.5); button.graphics.drawRect(x,y,width,height); button.graphics.endFill(); button.addEventListener(MouseEvent.CLICK, changeStatus); button.addEventListener(MouseEvent.MOUSE_OVER, changeColor); button.addEventListener(MouseEvent.MOUSE_OUT, changeColor); button.buttonMode = true; button.useHandCursor = true; button_color = new ColorTransform(); button_color.color = 0xff0000; button_color.alphaMultiplier = 0.5; button.transform.colorTransform = button_color; addChild(button_text); addChild(button); } // return status value public function getStatus():Boolean { return position; } // button action (What happens when you press button) private function changeStatus(myEvent:MouseEvent):void { if (getStatus() == true) { button_text.text = title1; obj.ButtonAction(obj_value); position = false; } else { button_text.text = title2; obj.ButtonAction(obj_value); position = true; } } // if mouse is over/out of button then change alpha chanel of button private function changeColor(myEvent:MouseEvent):void { if (button.transform.colorTransform.alphaMultiplier.toString() == '0.5') { button_color.alphaMultiplier = 0.8; } else { button_color.alphaMultiplier = 0.5; } button.transform.colorTransform = button_color; } } } // --- eriks_clases/Snake.as package eriks_clases { import flash.display.Sprite; import flash.events.TimerEvent; import flash.utils.Timer; import flash.geom.ColorTransform; public class Snake extends Sprite { // declaratinons private var snake:Sprite; // line that rotates private var snake_x:int; private var snake_y:int; private var snake_x_init:int; private var snake_y_init:int; private var snake_width:int; private var snake_height:int; private var snake_timer:Timer; private var snake_color:ColorTransform; // constructor public function Snake() { } // set properties to snake public function Create(x:int, y:int, width:int, height:int):void { snake_x = x; snake_y = y; snake_x_init = x; snake_y_init = y; snake_width = width; snake_height = height; snake = new Sprite(); snake.graphics.lineStyle(2, 0x00ff00, 1); snake.graphics.moveTo(snake_x_init, snake_y_init); //snake.graphics.curveTo(snake_x_init, snake_y_init, (snake_x_init + width), (snake_y_init + height)); snake_color = new ColorTransform(); snake_color.color = 65280; // the same 0x00ff00 snake.transform.colorTransform = snake_color; addChild(snake); snake_timer = new Timer(100); snake_timer.addEventListener(TimerEvent.TIMER, DrawSnake); } // Special functon for button interface. public function ButtonAction(... value):void { var status:Boolean; if (int(value[0]) == 0) { // play/pause snake if(snake_timer.running == true) snake_timer.stop(); else snake_timer.start(); } else if (int(value[0]) == 1) { // clear all snake drawings if (snake_timer.running == true) { status = true; snake_timer.stop(); } snake.graphics.clear(); snake.graphics.lineStyle(2, 0x00ff00, 1); snake.graphics.moveTo(snake_x_init, snake_y_init); snake_x = snake_x_init; snake_y = snake_y_init; if(status == true) { snake_timer.start(); } } else if (int(value[0]) == 2) { // change color of snake if (snake_timer.running == true) { status = true; snake_timer.stop(); } snake_color.color = int(value[1]); snake.transform.colorTransform = snake_color; if(status == true) { snake_timer.start(); } } } // draw snake private function DrawSnake(evt:TimerEvent):void { var x:int = Math.ceil(Math.random() * 10); var y:int = Math.ceil(Math.random() * 10); var pol:int = Math.ceil(Math.random() * 10); // make path if (pol < 6) { x = snake_x - x; y = snake_y - y; } else { x = snake_x + x; y = snake_y + y; } // borders of workplace if (x < 20) x = 20; if (x > snake_width) x = snake_width; if (y < 40) y = 40; if (y > snake_height) y = snake_height; snake_x = x; snake_y = y; snake.graphics.lineTo(snake_x, snake_y); } } }