Sunday, 18 April 2010

Unsmiley face class in Actionscript 3

I previously wrote a post called Unsmiley face in Actionscript 3 where I created an unhappy face using the drawCircle() and curveTo() methods from the AS3 graphics class. I have now created a class called unhappyFace shown below.

Update 10/06/10: If you don’t want an unsmiley face then I now have an option for a smiley face.

/**
* Unhappy face class
* Created by ILIKE2FLASH.COM
* Version 1
**/
package com.ilike2flash{

import flash.display.Shape;
import flash.display.MovieClip;

public class unhappyFace extends MovieClip {

private var my_shape:Shape=new Shape();
private var xposition:uint;
private var yposition:uint;
private var colour:uint;
private var lineThickness:uint;
private var happyFace:Boolean;

/*
* @param lThick The line thickness of the face.
* @param col The face colour.
* @param xpos The x position of the face.
* @param ypos The y position of the face.
* @param hf hf set true for smiley face.
*/
public function unhappyFace(lThick:uint, col:uint, xpos:int, ypos:int,hF:Boolean = false) {
addChild(my_shape);
colour=col;
lineThickness=lThick;
xposition=xpos;
yposition=ypos;
happyFace=hF;
drawFace();
}

private function drawFace():void {
my_shape.x=xposition;
my_shape.y=yposition;

my_shape.graphics.lineStyle(lineThickness);
my_shape.graphics.beginFill(colour);
my_shape.graphics.drawEllipse(0, 0, 195, 190);

my_shape.graphics.beginFill(0x000000);
my_shape.graphics.drawEllipse(45,47,24,37);
my_shape.graphics.drawEllipse(124,47,24,37);
my_shape.graphics.endFill();

if (happyFace) {
my_shape.graphics.moveTo(39,130);
my_shape.graphics.curveTo(100,200,160,130);
} else {
my_shape.graphics.moveTo(39,150);
my_shape.graphics.curveTo(110,120,161,150);
}

}
}
}

To use this class you need save the class file above in a folder call ‘ilike2flash’ within a folder class ‘com’. You then need to place the com folder in the same directory as your fla file or setup a class path. Then simply add the following code inside your fla file.
//Import the unhappyface class.
import com.ilike2flash.unhappyFace

//Create a new instance of the unhappy face class and add it onto the stage.
//If you want a smiley face then change the last parameter to true instead of false.
var myFace: unhappyFace = new unhappyFace(3, 0xFF3603, 0, 0,false);
addChild(myFace);

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP