FlashIDE色彩效果面板的秘密
美术喜欢调整MC(MovieClip)的属性面板里的色彩效果选项来修改MC的效果.其实Flash IDE里色彩效果面板的所有调整都可以通过 ColorTransform 类实现同样的效果.这样我们就能动态显示美术调好的效果。
阅读全文...
美术喜欢调整MC(MovieClip)的属性面板里的色彩效果选项来修改MC的效果.其实Flash IDE里色彩效果面板的所有调整都可以通过 ColorTransform 类实现同样的效果.这样我们就能动态显示美术调好的效果。
阅读全文...
今天看 优化 Flash 平台的性能 帮助文档时发现一个未公开的顶级函数 getSize()。
猜想getSize的接口可能是:
/**
* 获取对象的内存占用量
* @param p 任意类型,甚至是Class
* @return 一个数值,单位是byte
*/
public function getSize(p:*):uint;
不过这个方法只能在时间轴上使用,在类里就不能用了。
感谢jim提醒,原来这个方法在flash.sampler包下,请看 flash.sampler.getSize() 。
然后我测试了下flash里有没有内存对齐的概念。
不过获得的内存值都是4的倍数。
如果里面有属性占用为8,则结果则为8的倍数。
相关链接:
本文翻译至:http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html
知道C/C++ 有条件编译,一直想着AS要是也有条件编译就好了,今天搜了半天Google,终于让我找到了。
下面翻译livedocs.adobe.com上一篇文章,英文不怎么好,有些是Google翻译的,然后我再纠正下语句,大家不要见怪。
阅读全文...
首先Flash IDE 要安装 FlexComponentKit 扩展(没找到官方下载地址,所有传了以前下的CS3版本的)。
下面开始讲应用,先准备好自定义类,然后将这个类改个名字作为基类,比如我用的cn.lite3.MyUIMovieClip
,就用cn.lite3.MyUIMovieClipBase
,源码后面下载。
然后准备好要用的原件我的是MyUIMovieClip。
下面讲操作方法O(∩_∩)O。
阅读全文...
//像素级碰撞检测
package
{
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
public class HitTest
{
/**
* --------------------- 像素级碰撞检测
* @param target1 DisplayObject
* @param target2 DisplayObject
* @param accurracy Number 检测的精度 [0 , 1] 0 <= n <= 1
* @return Boolean
*/
public static function complexHitTestObject ( target1:DisplayObject, target2:DisplayObject, accurracy:Number = 1 ):Boolean
{
accurracy > 1 ? accurracy = 1 : 0;
return accurracy <= 0?false:complexIntersectionRectangle(target1,target2,accurracy).width != 0;
}
/**
* -------------------获取矩形边框重叠区域
* @param target1 DisplayObject
* @param target2 DisplayObject
* @return Rectangle
*/
public static function intersectionRectangle ( target1:DisplayObject, target2:DisplayObject ):Rectangle
{
// If either of the items don't have a reference to stage, then they are not in a display list
// or if a simple hitTestObject is false, they cannot be intersecting.
if ( !target1.root || !target2.root || !target1.hitTestObject( target2 ) )
{
return new Rectangle ;
}
// Get the bounds of each DisplayObject.
var bounds1:Rectangle = target1.getBounds( target1.root );
var bounds2:Rectangle = target2.getBounds( target2.root );
// Determine test area boundaries.
var intersection:Rectangle = new Rectangle();
intersection.x = Math.max( bounds1.x, bounds2.x );
intersection.y = Math.max( bounds1.y, bounds2.y );
intersection.width = Math.min( ( bounds1.x + bounds1.width ) - intersection.x, ( bounds2.x + bounds2.width ) - intersection.x );
intersection.height = Math.min( ( bounds1.y + bounds1.height ) - intersection.y, ( bounds2.y + bounds2.height ) - intersection.y );
return intersection;
}
/**
* -------------------------- 获取像素重叠区域
* @param target1 DisplayObject
* @param target2 DisplayObject
* @param accurracy Number 精度
* @return Rectangle
*/
public static function complexIntersectionRectangle ( target1:DisplayObject, target2:DisplayObject, accurracy:Number = 1 ):Rectangle
{
if ( accurracy <= 0 )
{
throw new Error("ArgumentError: Error #5001: Invalid value for accurracy",5001);
}
// If a simple hitTestObject is false, they cannot be intersecting.
if ( !target1.hitTestObject( target2 ) )
{
return new Rectangle ;
}
var hitRectangle:Rectangle = intersectionRectangle( target1, target2 );
// If their boundaries are no interesecting, they cannot be intersecting.
if ( hitRectangle.width * accurracy <1 || hitRectangle.height * accurracy <1 )
{
return new Rectangle ;
}
var bitmapData:BitmapData = new BitmapData( hitRectangle.width * accurracy, hitRectangle.height * accurracy, false, 0x000000 );
// Draw the first target.
bitmapData.draw ( target1, HitTest.getDrawMatrix( target1, hitRectangle, accurracy ), new ColorTransform( 1, 1, 1, 1, 255, -255, -255, 255 ) );
// Overlay the second target.
bitmapData.draw ( target2, HitTest.getDrawMatrix( target2, hitRectangle, accurracy ), new ColorTransform( 1, 1, 1, 1, 255, 255, 255, 255 ), BlendMode.DIFFERENCE );
// Find the intersection.
var intersection:Rectangle = bitmapData.getColorBoundsRect( 0xFFFFFFFF,0xFF00FFFF );
bitmapData.dispose ();
// Alter width and positions to compensate for accurracy
if ( accurracy != 1 )
{
intersection.x /= accurracy;
intersection.y /= accurracy;
intersection.width /= accurracy;
intersection.height /= accurracy;
}
intersection.x += hitRectangle.x;
intersection.y += hitRectangle.y;
return intersection;
}
/**
* -------------------------获取MC的矩阵
* @param target DisplayObject
* @param hitRectangle Rectangle
* @param accurracy Number
* @return Matrix
*/
protected static function getDrawMatrix ( target:DisplayObject, hitRectangle:Rectangle, accurracy:Number ):Matrix
{
var localToGlobal:Point;
var matrix:Matrix;
var rootConcatenatedMatrix:Matrix = target.root.transform.concatenatedMatrix;
localToGlobal = target.localToGlobal( new Point( ) );
matrix = target.transform.concatenatedMatrix;
matrix.tx = localToGlobal.x - hitRectangle.x;
matrix.ty = localToGlobal.y - hitRectangle.y;
matrix.a = matrix.a / rootConcatenatedMatrix.a;
matrix.d = matrix.d / rootConcatenatedMatrix.d;
if ( accurracy != 1 )
{
matrix.scale ( accurracy, accurracy );
}
return matrix;
}
}
}