月度存档: 5 月 2013

textarea设置

[code]
var tf:TextFormat = new TextFormat();
tf.size = 25;
tf.color = 0xff00ff;
tv.defaultTextFormat = tf;
tv.text = JsonData.version;
//for debug

var _txt:TextArea = new TextArea();
addChild(_txt);
_txt.height = this.stage.stageHeight-100;
_txt.width = 1000;
_txt.x = 450;
_txt.y = 50;
_txt.visible = false;
_txt.setStyle(“textFormat”, tf);
txt.validateNow(); //总是显示最后一行 _txt.verticalScrollPosition=_txt.maxVerticalScrollPosition;[/code]

转:在64位操作系统上使用FlashDevelop的Debug功能

原始链接:http://zengrong.net/post/1692.htm
最近用上了FlashDevelop。与Flash Builder比起来,它确实优点很多:小巧,快速,灵活的定制功能,免费且开源。
使用FlashDevelop开发AS/Flex/AIR程序的时候,可以使用Flex SDK来编译和调试。Flex SDK使用JAVA写成,需要系统中安装JAVA虚拟机(JVM)。而我的系统中已经安装了64位的JAVA虚拟机。

在调试的时候,FlashDevelop报告了下面的错误。

Debugger startup error: System.BadImageFormatException: 试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
在 net.sf.jni4net.jni.JNI.Dll.JNI_GetDefaultJavaVMInitArgs(JavaVMInitArgs* args)
在 net.sf.jni4net.jni.JNI.Init()
在 net.sf.jni4net.jni.JNI.CreateJavaVM(JavaVM& jvm, JNIEnv& env, Boolean attachIfExists, String[] options)
在 net.sf.jni4net.Bridge.CreateJVM()
在 net.sf.jni4net.Bridge.CreateJVM(BridgeSetup setup)
在 FlashDebugger.DebuggerManager.Start(Boolean alwaysStart)

FlashDevelop是直接调用Flex SDK中的fdb进行调试的,出现这个错误的原因,是因为fdb仅支持32位的JVM。

可是,JAVA不是平台无关的么?为什么fdb却只能支持32位的JVM?

的确,纯JAVA程序确实是平台无关的,但是调用了JNI就不同了,JNI是受平台限制的。而通过上面的报错信息,明显能看出是JNI在报错。

找到了问题所在,解决起来就容易了。
下面是解决步骤:

安装32位的JVM。JVM是允许32位和64位共存的。
将环境变量JAVA_HOME改为指向32位JVM的安装路径。
搞定。
但是,在64位操作系统中修改JAVA_HOME环境变量指向32位JVM是个愚蠢的做法。因为这样会导致操作系统中默认使用32位的JVM。所以,有个稍微麻烦一点的办法。

安装32位的JVM。我的JVM 32bit安装在C:\Program Files (x86)\Java\jre7目录。
在FlashDevelop.exe文件相同的目录下创建一个startFD.bat文件,写入如下内容:

set JAVA_HOME=C:\Program Files (x86)\Java\jre7
start FlashDevelop.exe
双击startFD.bat,程序会首先设置JAVA_HOME变量,然后启动FlashDevelop,并关闭cmd窗口。
使用这种方式设置的JAVA_HOME环境变量,只在启动FlashDevelop.exe的时候有效,不会影响系统的已有的环境变量。

网上还能搜到一些其它的解决方案,让我们来看看:

方案1,来源

复制 jre\bin中的msvcr71.dll到Windows\System32下就可以了

这个方案明显是针对32位操作系统的,所以解决不了本文的问题。

方案2,来源

Googling about this problem tells that many users have this in JDK 6 solved with msvcr71.dll, but not for me
And it’s because I have latest JDK 7 which needs msvcr100.dll, so just find this DLL in “jre7/bin” directory and copy to FlashDevelop.exe folder.
For thos who had BadImage problem while building on x64 system, don’t forget, that now FD4 uses x32 component, so set JAVA_HOME to point to x32 version of JDK.

这个方案说的比较详细,也指明了JDK7与JDK6所需的msvcr*.dll并不相同。不过按这个方案也是解决不了本文的问题的。倒是最后那句话给了我解决问题的启示。

flashplayer官方安装地址

http://www.adobe.com/support/flashplayer/downloads.html

音乐发烧友有福了

http://jing.fm/

As3读取CSV文件

google上有个开源库:https://code.google.com/p/csvlib/
基本用法:
[code]
package
{
import com.shortybmc.data.parser.CSV;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;

/**
* …
* @author Amyflash.com
*/
public class Main extends Sprite
{
private var _csv : CSV;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
handleCSV();
}

private function handleCSV():void
{
_csv = new CSV( new URLRequest(‘example-1.csv’) );
_csv.addEventListener ( Event.COMPLETE, completeHandler );
}

private function completeHandler ( event : Event ):void
{
//trace ( _csv.data.join(‘\r’) )
trace(_csv.header[0]+”\n”);
trace(_csv.data[0][0]);
// do something …
}

}

}
[/code]

转:as3.0像素级碰撞检测

[code]//像素级碰撞检测
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; } } }[/code]

As3加速度测试

[code]stage.addEventListener(MouseEvent.MOUSE_DOWN,doClick);
stage.addEventListener(MouseEvent.MOUSE_UP,doClick2);
addEventListener(Event.ENTER_FRAME,doE);
var clicked:Boolean = false;
var vx:Number = 0;
var ax:Number = .2;
function doClick(e:MouseEvent):void
{
clicked = true;
}
function doClick2(e:MouseEvent):void
{
clicked = false;
}

function doE(e:Event):void
{
test.x = mouseX;
if (! clicked)
{

vx += ax;
test.y += vx;
}
else
{
vx -= ax;
test.y += vx;
}

}[/code]

检查haxe安装库的命令

haxelib list