Label

  • ActionScript 2
  • AD Player 2
  • Algorithm 2
  • AS3 16
  • Audio 1
  • Audio Description Player 1
  • Bitmap 1
  • BitmapData 1
  • Browser 1
  • C# Experience 4
  • Chart 1
  • Flash 10
  • Game 1
  • Geometry 1
  • JavaScript 2
  • Mathematics 6
  • Music Online 1
  • MVC 1
  • Performance 1
  • PureMVC 1
  • Slide 1
  • Talks 1
  • Tool 1
  • Tool Player 1
Toggle Side
Home   »   Flash   »   DataMix

DataMix

Version 1.0.0.1
DataMix is a fundamental component allows to convert from MovieClip to Animal Bitmap, DataMix store the BitmapData's after analysis & processing from MovieClip with methods basic: width, hight, total BitmapData.

The constructor:

/**
* In special cases, we only get the size, no need to get data
* @param mc as MovieClip with multiple frames
*/
public function DataMix(mc:MovieClip)
The basic property public:

// mc as MovieClip with multiple frames
var dm:DataMix = new DataMix(mc);
dm.width; // as Number
dm.hight; // as Number
dm.data; // as Array [BitmapData,BitmapData,BitmapData,...]


The basic methods private:

//[1] function support
function movePosition(a:Number, b:Number):Number;
function dePercent(p:Number, s:Number = 0, e:Number = 100):Number;
//[2]
function getRecBase(mc:MovieClip):Rectangle;
function getListBase(mc:MovieClip, rec:Rectangle):Array;
function getBaseBitmapData(mc:MovieClip, rec:Rectangle, smoothing:Boolean ): BitmapData;
//[3]
function getRecActual(list:Array,rec:Rectangle):Rectangle;
function getViboty(mc:BitmapData,rec:Rectangle): Rectangle
function getListActual(list:Array, newrec:Rectangle):Array;
function getActutalBitmapData(bitmapdata:BitmapData, rec:Rectangle): BitmapData;

[2]
Figure 1: Get list BitmapData base
[3]

Figure 2: Get lis BitmapData from list BitmapData base

The last reference:
18 Useful mathematical formulas in ActionScript 3
MovieClip to Animal Bitmap

Source:
DataMix.as version 1.0.0.1



Version 1.0.0.2
In this version, DataMix only get true size of the MovieClip, it's not store the BitmapData
Changes in the Constructor

/**
* In special cases, we only get the size, no need to get data
* @param mc as MovieClip
* @param isdata if true get all including data else false only get size
*/
public function DataMix(mc:MovieClip,isdata:Boolean=true)

For example:
// mc as MovieClip with multiple frames
var dm:DataMix = new DataMix(mc);
dm.width; // 100
dm.hight; // 100
dm.data; // null

Source:
DataMix.as version 1.0.0.2



Version 1.0.0.3

Completely remove the excess in list BitmapData, you can see the difference in version 1 2 and 3

/**
* @param mc Make sure you seted the movie correctly!
*/
private function setup(mc:MovieClip,isdata:Boolean):void {
var recBase:Rectangle = getRecBase(mc);
var listBase:Array = getListBase(mc, recBase);
var recActual:Rectangle = getRecActual(listBase, recBase);

var listFace:Array = getListActual(listBase, recActual);
var recTrim:Rectangle = getTrimBitmapData(listFace);

w = recTrim.width;
h = recTrim.height;

if (isdata) {
clearListBase(listBase); // necessary!
d = getListActual(listFace, recTrim);
}else {
clearListBase(listBase); // necessary!
clearListBase(listFace); // necessary!
d = null;
}
}
/**
* The function trim a bit transparent in the Bitmapdata
* @param a list BitmapData actual, but non-trim
* @return rectangle
*/
private function getTrimBitmapData(a:Array):Rectangle {
var maxx:Number = NaN;
var maxy:Number = NaN;
var minx:Number = NaN;
var miny:Number = NaN;
var maxw:Number = NaN;
var maxh:Number = NaN;
var temp:Number = NaN;
for (var i:int = 0 ; i < a.length; i++){
var b:Rectangle = a[i].getColorBoundsRect(0xFFFFFFFF, 0x000000, false);

minx = ((temp = b.x) < minx)?temp:(isNaN(minx))?temp:minx;
miny = ((temp = b.y) < miny)?temp:(isNaN(miny))?temp:miny;
maxw = ((temp = b.width) > maxw)?temp:(isNaN(maxw))?temp:maxw;
maxh = ((temp = b.height) > maxh)?temp:(isNaN(maxh))?temp:maxh;

maxx = ((temp = b.x + b.width) > maxx)?temp:(isNaN(maxx))?temp:maxx;
maxy = ((temp = b.y + b.height) > maxy)?temp:(isNaN(maxy))?temp:maxy;

}
var maxwi:Number = maxx - minx;
var maxhi:Number = maxy - miny;
return new Rectangle(minx, miny, maxwi, maxhi);
}



Figure 3: Get trim BitmapData, completely remove the transparent

For example:

Old version (left ) and new version (right)

Source:
DataMix.as version 1.0.0.3


Version 1.0.0.4

Creating source BitmapData that is used for a large image with contains render multiple images children.

// mc as MovieClip with multiple frames
var dm:DataMix = new DataMix(mc);
//Return value bitmapData that is parse from data.
dm.bitmap; // as big BitmapData;

For example:
var dx:DataMix = new DataMix(mc); // mc as MovieClip with multiple frames
var bitmap:Bitmap = new Bitmap(dx.bitmap);
addChild(bitmap);
Bitmap is taken from DataMix

Source:
DataMix.as version 1.0.0.4










Labels: ActionScript ,  AS3 ,  Bitmap ,  BitmapData ,  Flash   at:  4:18 PM     Email This BlogThis! Share to X Share to Facebook

0 comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments ( Atom)
© Hung Le 2007-2016. Powered by Blogger