Anda di halaman 1dari 5

These codes will help you in creation of Android application using

Adobe Flash Professional CS6


13
/* Pencil Tool shape, everything drawn with this tool and the eraser tool is
stored inside board.pencilDraw */
var pencilDraw:Shape = new Shape();
/* Text format */
var textformat:TextFormat = new TextFormat();
/* Colors */
var colorsBmd:BitmapData; //We'll use this Bitmap Data to get the pixel RGB
Value when clicked
var pixelValue:uint;
var activeColor:uint = 0x000000; //This is the current color in use,
displayed by the shapeSize MC
/* Save dialog instance */
var saveDialog:SaveDialog;
{
board.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilTool); //Stops
the drawing
}

17
private function EraserTool(e:MouseEvent):void
{
/* Quit active tool */
quitActiveTool();
/* Set to Active */
active = "Eraser";
/* Listeners */
board.addEventListener(MouseEvent.MOUSE_DOWN, startEraserTool);
board.addEventListener(MouseEvent.MOUSE_UP, stopEraserTool);
/* Highlight */
highlightTool(eraser);
hideTools(pencil, txt);

/* Use White Color */


ct.color = 0x000000;
shapeSize.transform.colorTransform = ct;
}
private function startEraserTool(e:MouseEvent):void
{
pencilDraw = new Shape();
board.addChild(pencilDraw);
pencilDraw.graphics.moveTo(mouseX, mouseY);
pencilDraw.graphics.lineStyle(shapeSize.width, 0xFFFFFF); //White Color
board.addEventListener(MouseEvent.MOUSE_MOVE, drawEraserTool);
}
private function drawEraserTool(e:MouseEvent):void
{
pencilDraw.graphics.lineTo(mouseX, mouseY);
}
function stopEraserTool(e:MouseEvent):void
{
board.removeEventListener(MouseEvent.MOUSE_MOVE, drawEraserTool);
}

18
private function TextTool(e:MouseEvent):void
{
/* Quit active tool */
quitActiveTool();
/* Set to Active */
active = "Text";
/* Listener */
board.addEventListener(MouseEvent.MOUSE_UP, writeText);
/* Highlight */
highlightTool(txt);
hideTools(pencil, eraser);
}
private function writeText(e:MouseEvent):void
{

/* Create a new TextField Object, this way we won't replace older


instances */
var textfield = new TextField();
/* Set Formats, position, and focus */
textfield.type = TextFieldType.INPUT;
textfield.autoSize = TextFieldAutoSize.LEFT;
textfield.defaultTextFormat = textformat;
textfield.textColor = activeColor;
textfield.x = mouseX;
textfield.y = mouseY;
stage.focus = textfield;
/* Add text to Board */
board.addChild(textfield);
}

19
private function export():void
{
var bmd:BitmapData = new BitmapData(600, 290);//Creates a new BitmapData
with the board size
bmd.draw(board);//Draws the board MovieClip into a BitmapImage in the
BitmapData
var ba:ByteArray = PNGEncoder.encode(bmd); //Creates a ByteArray of the
BitmapData, encoded as PNG
var file:FileReference = new FileReference(); // Instantiates a new File
Reference Object to handle the save
file.addEventListener(Event.COMPLETE, saveSuccessful); //Adds a new
listener to listen when the save is complete
file.save(ba, "MyDrawing.png"); //Saves the ByteArray as a PNG
}
private function saveSuccessful(e:Event):void
{
saveDialog = new SaveDialog();// Instantiates a new SaveDialog Class
addChild(saveDialog); //Adds the SaveDialog MovieClip to the Stage
saveDialog.closeBtn.addEventListener(MouseEvent.MOUSE_UP,
closeSaveDialog);//Adds a listener to the close button of the dialog
}
private function closeSaveDialog(e:MouseEvent):void
{

removeChild(saveDialog); //Removes the dialog of the Stage


}
private function save(e:MouseEvent):void
{
export(); //Calls the export function to begin the saving process
}

20
private function clearBoard(e:MouseEvent):void
{
/* Create a white rectangle on top of everything */
var blank:Shape = new Shape();
blank.graphics.beginFill(0xFFFFFF);
blank.graphics.drawRect(0, 0, board.width, board.height);
blank.graphics.endFill();
board.addChild(blank);
}

21
private function convertToBMD():void
{
colorsBmd = new BitmapData(colors.width,colors.height);
colorsBmd.draw(colors);
}
private function chooseColor(e:MouseEvent):void
{
pixelValue = colorsBmd.getPixel(colors.mouseX,colors.mouseY);//Gets the
cliked pixel RGB value
activeColor = pixelValue;
/* Use a ColorTransform object to change the shapeSize MovieClip color */
ct.color = activeColor;
shapeSize.transform.colorTransform = ct;
}

24
private function addListeners():void
{
pencilTool.addEventListener(MouseEvent.MOUSE_UP, PencilTool);
eraserTool.addEventListener(MouseEvent.MOUSE_UP, EraserTool);
textTool.addEventListener(MouseEvent.MOUSE_UP, TextTool);

saveButton.addEventListener(MouseEvent.MOUSE_UP, save);
clearTool.addEventListener(MouseEvent.MOUSE_UP, clearBoard);
colors.addEventListener(MouseEvent.MOUSE_UP, chooseColor);
sizePanel.addEventListener(MouseEvent.MOUSE_UP, changeShapeSize);
shapeSize.addEventListener(MouseEvent.MOUSE_UP, changeShapeSize);
}

Anda mungkin juga menyukai