flash effects with bitmapdata
Flash is great!!
This movie requires Flash Player 9
This code show how to create falling hearts with flash cs4
you can also use the code for cs3
create a movieclip with a heart in your library
package {
import flash.display.MovieClip;
import flash.events.*;
public class fallingheart extends MovieClip {
public function fallingheart() {
for (var i = 0; i < 30; i ++) {
var h:heart = new heart();
h.x=Math.round(Math.random()*stage.stageWidth);
h.y=Math.round(Math.random()*stage.stageHeight);
h.scaleX = h.scaleY = .4+ ((Math.random()*1)/2);
h.swing = 15 + (Math.random()*15);
h.n=Math.random()*2;
h.speed = 1 + (Math.random()*4);
addChild(h);
h.addEventListener(Event.ENTER_FRAME, onEnterLoop);
//h.onEnterFrame = fall;
}
}
//-- you can also use timer to call this
public function onEnterLoop(e:Event) {
trace(stage.stageHeight);
var h:heart=e.currentTarget as heart;
h.y+=h.speed;
h.n+=0.25;
h.rotation=Math.cos(h.n)*h.swing;
if (h.y>stage.stageHeight) {
h.x=Math.round(Math.random()*stage.stageWidth);
h.y=-50;
}
}
}
}
The below code shows how to use the class
import druva.NumberUtil;
trace('500', NumberUtil.getParity(500));
// true
trace('489', NumberUtil.getParity(489));
// false
trace('5', NumberUtil.getParity(5));
//false
trace('1', NumberUtil.getParity(1));
//true
trace('400', NumberUtil.getParity(400));
//false
This is the actual class
package druva {
import flash.display.Sprite;
public class NumberUtil extends Sprite{
public function NumberUtil(){
}
public static function getParity(num:Number):String {
return (num % 2) ? 'odd' : 'even';
}
}
}
Convert TextField to Bitmap
package {
import flash.display.*;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
public class BitmapUtils extends Sprite {
public function BitmapUtils() {
addChild(tf2bm('Druva'));
}
public function tf2bm(str:String) {
var fmt:TextFormat;
var bmd:BitmapData;
var bm:Bitmap;
var tf:TextField;
fmt = new TextFormat();
fmt.font='Verdana';
fmt.size=30;
tf = new TextField();
tf.text=str;
tf.setTextFormat(fmt);
tf.autoSize=TextFieldAutoSize.LEFT;
bmd=new BitmapData(tf.width,tf.height,true,0);
bmd.draw(tf);
bm=new Bitmap(bmd);
bm.smoothing=true;
return bm
}
}
}
The below code shows how to use the class
import druva.NumberUtil; trace(NumberUtil.getRand(5, 10));
This is the actual class for validation
package druva{
import flash.display.Sprite;
public class NumberUtil extends Sprite {
public function NumberUtil() {
}
public static function getRand(min:Number, max:Number):Number {
return Math.floor(Math.random()*(max+1-min))+min;
}
}
}
import flash.display.Sprite;
import flash.text.*;
function glyph(){
var strFontName:String = "Wingdings";
var givenFont:Font;
var enumeratedfonts:Array = Font.enumerateFonts(true);
for (var i:int = 0; i < enumeratedfonts.length; i++) {
if (enumeratedfonts[i].fontName == strFontName) {
givenFont = enumeratedfonts[i];
break;
}
}
trace(givenFont.hasGlyphs("blog.totusinfo.com"));
}
glyph();