Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
- //COMMENTS ARE IN DOUBLE SLASH, PLEASE READ THEM VERY CAREFULLY, dont understand anything,
- //js call me ok
- //Creating null variables before initialization to store stage objects
- var stain:StainBlack;
- var cuiBrush:BrushCui;
- var upzBrush:BrushCui;
- var empty:Empty;
- var empty1:Empty;
- var selected:int = 0; // 0= nth, 1=cui,2=good
- //Holding values
- var cleaning:Boolean = false;
- var opacity:Number = 0;
- //Called on initialization of object
- function init():void{
- //Constructor - This is defined by right click library > Advance > ActionScript
- //Linkage > Class > (the class name +() will be the constructor of the object type)
- stain = new StainBlack();
- cuiBrush = new BrushCui();
- upzBrush = new BrushCui();
- empty = new Empty();
- empty1 = new Empty();
- //Global event handlers, passing delegates to child objects
- stage.addEventListener(MouseEvent.MOUSE_DOWN, startCleaning);
- stage.addEventListener(MouseEvent.MOUSE_MOVE, inCleaning);
- stage.addEventListener(MouseEvent.MOUSE_UP, endCleaning);
- //Selecting the brush
- cuiBrush.addEventListener(MouseEvent.CLICK,
- function():void{
- selected = 1;
- }
- );
- upzBrush.addEventListener(MouseEvent.CLICK,
- function():void{
- selected = 2;
- }
- );
- //Adding the newly created objects (at line 20 and 21) to the stage
- addChild(stain);
- addChild(empty);
- addChild(empty1);
- addChild(cuiBrush);
- addChild(upzBrush);
- //Sets the coordinates of stain n cuibrush on stage
- stain.x = 500;
- stain.y = 500;
- cuiBrush.x = 200;
- cuiBrush.y =50;
- upzBrush.x =100;
- upzBrush.y =50;
- //Resize the stain to be smaller
- stain.width = 300;
- stain.height= 300;
- //NOT SURE WHAT THESE IS SUPPOSE TO DO??
- /*
- wallBracket_mc.cuiBrush_mc.addEventListener(MouseEvent.CLICK, function():void{
- opacity = 0.3
- cuiBrush_mc.startDrag("true");
- Mouse.hide();
- cui = true;
- });
- wallBracket_mc.upzBrush_mc.addEventListener(MouseEvent.CLICK, function():void{
- opacity = 1.0
- upzBrush_mc.startDrag("true");
- Mouse.hide();
- });
- */
- //this is when click on wall bracket swap, but i will remove it for now
- //swapChildren(clean_mc, wallBracket_mc);
- }
- //Calling initialization
- init();
- //The cleanning called to start cleaning (called when the mouse is down ANYWHR on the screen)
- function startCleaning(e:MouseEvent):void{
- //Sys out for debugging
- trace("You have begun cleaning");
- //Raises the cleaning flag
- cleaning = true;
- empty.graphics.lineStyle(100,0xffffff,0.5);
- empty1.graphics.lineStyle(100,0xffffff,1.0);
- if(selected==1){
- //The bursh to mouse position
- cuiBrush.x = mouseX;
- cuiBrush.y = mouseY-cuiBrush.height+5;
- }else if(selected == 2){
- upzBrush.x = mouseX;
- upzBrush.y = mouseY-upzBrush.height+5;
- }
- }
- //Check whether the first 2 poarameters are within the 3-6th parameters (in whether the mouse is
- //over the box
- function withinBB(mx:Number, my:Number, xi:Number, yi:Number, xsize:Number,ysize:Number):Boolean{
- if(mx > xi && mx < xi+xsize){
- if(my>yi && my<yi+ysize){
- return true;
- }
- }
- return false;
- }
- //Called when the mouse move ANYWHR on the screen
- function inCleaning(e:MouseEvent):void{
- /*Check if the cleaning flag is raised
- if(cleaning && withinBB(mouseX,mouseY,stain.x,stain.y,stain.width,stain.height)){
- //Added a listener to the stain, to change its own transparency to half if,
- //if the bursh is moving
- stain.addEventListener(MouseEvent.MOUSE_MOVE, function():void{
- stain.graphics.lineTo
- });
- }*/
- //While mouse is moving, move the bursh to the mouse
- if(cleaning && selected == 1){
- cuiBrush.x = mouseX;
- cuiBrush.y=mouseY-cuiBrush.height+5;
- empty.graphics.lineTo(mouseX,mouseY);
- if(withinBB(mouseX,mouseY,stain.x,stain.y,stain.width,stain.height)){
- if(Math.random()>0.01){
- littering(Math.round(Math.random()*2),mouseX, mouseY+5);
- }
- }
- }
- if(cleaning && selected == 2){
- upzBrush.x = mouseX;
- upzBrush.y = mouseY-upzBrush.height+5;
- empty1.graphics.lineTo(mouseX,mouseY);
- }
- }
- function littering(num:int, cx:Number, cy:Number):void{
- for(var i:int = 0; i<num; i++){
- var litter:MovieClip;
- var yyy:int = Math.round(Math.random()*3);
- trace("Random Value: "+yyy);
- switch(yyy){
- case 0:
- litter = new RedBig();
- break;
- case 1:
- litter = new RedSmall();
- break;
- case 2:
- litter = new GreenBig();
- break;
- case 3:
- litter = new GreenSmall();
- break;
- default: break;
- }
- litter.rotation = Math.random()*360;
- litter.width = (Math.random()*0.4+0.8)*litter.width;
- litter.height = (Math.random()*0.4+0.8)*litter.height;
- litter.x = Math.random() > 0.5 ? -Math.random()*8 + cx : Math.random()*8 + cx;
- litter.y = Math.random() > 0.5 ? -Math.random()*8 + cy : Math.random()*8 + cy;
- addChild(litter);
- }
- }
- //Lower the cleaning flag
- function endCleaning(e:MouseEvent):void{
- trace("You have stopped cleaning");
- cleaning = false;
- selected =0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement