Recently in Haxe Category

首先请遵守开源项目的相关约定,在下面相应的链接你可以找到,以下都是我对于列举的开源项目的个人看法,本来准备早点写的,因为一些事情所以现在才发出来

flasm:是Flash 8及更早版本的提供命令行的Flash ActionScript汇编和反汇编,优化Actionscript,在ActionScript3中没有相应的,最早可以追溯至2001年,我记得最早我是在闪客帝国中看到的,想起那时候还是个小屁孩,什么都不同,国内还是闪客兴起的时代,遥远的年代。

hxASM:这个可以支持ActionScript3的汇编,以前提及过hxASM:给你的as程序提速30%哦(大致翻译官网的)Haxe 长进了还有FDT又升级了,顺便提下Haxe:蛮有趣网络的语言,目标蛮大的,希望更新接上去,不过最近mail list倒是蛮火的--相对以前来说。

C preprocessor for ActionScript:正如名字,把C预编译跟ActionScript结合,支持Flex SDK2和ActionScirpt3,基本上预编译的好处、宏之类的都有,挺喜欢,只是太久没有接触C了,难免有点陌生了,还得熟悉熟悉,用于代码编译控制那个方便亚

FAR(FlashArchive):另一个组织数据的解决方案,当然提供数据压缩和重复利用之类的功能,个人觉得很不错,而且官网举的例子是PaperVesion3D,对大数据有个更好更安全的方案。

Haxe:这个上面已经提及到了,不仅是ActionScript,同时对JavaScript/AJAX以及服务端代码也提供支持。

Pair:Python是很强大滴,这个是Python应对Air的解决方案,点开官网,示意图会一目了然,Python的作用还是很清晰的,只是不知道现在AIR的普及率达到什么程度,不过Google Analytics Reporting Suite的AIR版的作者在官网上说30%使用者来自中国,所以特意加了中文版上去。

XIFF:以前写过一篇有提及开始使用Openfire,蛮有前景的,不过国内应用还是太少,国外很多都是ActionScript2的

 

当然还有很多大家都比较熟悉的就不在这里提及了,比如PaperVesion3D、APE、AMFPHP以及WebORB、AsUnit、FlexUnit、Red5、JSON...

终于补充好了

Good Luck & Have Fun!

是我的疏忽,一直没事看haxe都忘了看这个神奇的东西

看看介绍:

hxASM enables you to program directly in Flash9 assembler and it will compile for your a SWF compatible with Flash Player 9 that can be either directly loaded from memory or saved into a file.

The library can dynamicaly generate a ByteArray representing a SWF file that contains the compiled assembler methods. The code can then be executed by using the flash.display.Loader.loadBytes method.

hxASM可以让你在Flash9平台汇编级别编程,它会帮你编译好一个与Flash9平台相兼容的SWF,之后你可以载入到内存或者保存为一个文件

这个库可以动态生成一个ByteArray来表征一个包含汇编程序的方法的SWF,你的汇编代码可以用flsah.display.Loader.loadBytes来载入和执行,太帅了

这个是hxasm的地址:http://haxe.org/hxasm

如果你还没有配置好你的haxe

那很简单的

http://haxe.org/download这里可以下载haxe所需要的,找好你平台对应的,上面那三个都是下载一个小东西帮你再联网下载安装需要的东东,如果不爽就自己下,其实也很简单的,点击下就ok了

不过还是用人家的啦,都不知道是不是改了环境变量--具体没细看这个

开发环境用Flash Develop,目前是3.0 beta4,需要.net framework 2.0,去FD官网http://www.flashdevelop.org/community下载吧,都有的

至于他说的haxeFD是不需要的,FD3自己带了

 

你可以完全按照http://haxe.org/hxasm来试试效果

不过我试了下,发现版本升迁有点点小问题(可能是我鹾,大家试试如果ok告诉下我)

运行刚才下载的hxinst-win.exe,会帮你配置haxe和neko,后者是环境,配置看这里http://nekovm.org/doc/begin,如果是用hxinst-win.exe就不用管他啦

"我的电脑"属性 -- 高级 -- 环境变量:

HAXEPATH   C:\Program Files\Motion-Twin\haxe\

NEKO_INSTPATH    C:\Program Files\Motion-Twin\neko

你配置的时候也是这样的,只要添加个环境变量就OK啦

 

好了,现在运行下cmd.exe

cd C:\Program Files\Motion-Twin\haxe

haxelib install hxasm

这样会去下载hxasm包,我下载到的是1.04版本,之后会生成一个xml就是包配置文件

不过很郁闷的是-lib hxasm加到编译参数那,我这边老是不行,可能是不使用haxeFD用的是FD的HaXeContext吧

不过HaXeContext的Additional Compiler Option加上-lib hxasm也不行

所以最后我把hxasm这个类包copy出来了,其实大家看install好的hxasm,下一级的1.04居然是1,04,这个没有深入去弄,FD论坛上逛了一圈木有什么发现

 

好了,新建一个空haxe项目,名字TestHxasm,地址自己分配一个

新建一个class,命名Test.hx

把下面代码贴上去(就是官网的)

import hxasm.Bytecode;
 
class Test {
 
    static var loader : flash.display.Loader;
 
    static function main() {
// create a new bytecode Context
var ctx = new hxasm.Context();
// 定义 Main类
ctx.beginClass("Main");
// 定义flash9的int类型
var tint = ctx.type("int");
// 创建成员函数 'test'
        // 下面定义是表明test函数参数为空,返回值为tint就是flash9的int
var m = ctx.beginMethod("test",[],tint);

//下面还是保持原来注释比较好
 // the maximum size of the stack in this method
m.maxStack = 1;
// write bytecode into the current method
ctx.ops([
    OInt(666),
    ORet,
]);
// we are done with all the bytecode writing
ctx.finalize();
 
// create an output and write the bytecode to it
var o = new hxasm.Output();
hxasm.Writer.write(o,ctx);
var swf = o.getBytes();
 
// load the SWF bytes
loader = new flash.display.Loader();
loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE,onLoaded);
loader.loadBytes(swf);
    }
 
    // the data has been succesfully loaded
    public static function onLoaded(e) {
// get the Main class
var m = loader.contentLoaderInfo.applicationDomain.getDefinition("Main");
// 在这里,你可以trace下inst和m,可以发现是什么,这点跟as3都差不多create an instance of it
var inst : Dynamic = Type.createInstance(m,[]);
// call the 'test' method
trace(inst.test());
// this should display '666'
    }
 
}

之后记得把hxasm包复制进来就好了,项目属性那定义一个swf生成和swf版本,之后在compiler那设置入口类为Test

F5测试下吧

 

来点更爽的,也就是官网上的斐波那契函数

试试这段

import hxasm.Bytecode;
 
class Test {
 
    static var loader : flash.display.Loader;
 
    static function main() {
  var ctx = new hxasm.Context();
  ctx.beginClass("Main");
  var tint = ctx.type("int");
  var m = ctx.beginMethod("fib",[tint],tint);
  m.maxStack = 3;
  ctx.ops([
   OReg(1),      // register 1 = first argument
   OSmallInt(1), // the integer 1
   OJump(JGt,3), // jump 3 bytes if reg1 > 1
   OInt(1),
   ORet,         //   return 1
   ODecrIReg(1), // decrement register 1
   OThis,
   OReg(1),
    // call this.fib(reg1) with 1 argument
   OCallProperty(ctx.property("fib"),1),
   ODecrIReg(1), // decrement register 1
   OThis,
   OReg(1),
    // call this.fib(reg1) with 1 argument
   OCallProperty(ctx.property("fib"),1),
   OOp(OpIAdd),  // add the two values
   ORet,         // returns
  ]);
  ctx.finalize();
  
  var o = new hxasm.Output();
  hxasm.Writer.write(o,ctx);
  var swf = o.getBytes();

  loader = new flash.display.Loader();
  loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE,onLoaded);
  loader.loadBytes(swf);
    }

    public static function onLoaded(e) {
 var m = loader.contentLoaderInfo.applicationDomain.getDefinition("Main");
 var inst : Dynamic = Type.createInstance(m,[]);
 trace(inst.fib(30));
    }
 
}

记得inst.fib()参数不要太凶狠,不然堆栈溢出

其他版本的

import hxasm.Bytecode;
 
class Test {
 
    static var loader : flash.display.Loader;
 
    static function main() {
  var ctx = new hxasm.Context();
  ctx.beginClass("Main");
  var tint = ctx.type("int");
  var m = ctx.beginMethod("fib",[tint],tint);
  m.maxStack = 3;
  ctx.ops([
   OReg(1),
   OSmallInt(1),
  ]);
  var j = ctx.jump(JGt); // prepare a jump
  ctx.ops([
   OInt(1),
   ORet,
  ]);
  j(); // patch the jump with current position
  ctx.ops([
   ODecrIReg(1),
   OThis,
   OReg(1),
   OCallProperty(ctx.property("fib"),1),
   ODecrIReg(1),
   OThis,
   OReg(1),
   OCallProperty(ctx.property("fib"),1),
   OOp(OpIAdd),
   ORet,
  ]);
  ctx.finalize();
  
  var o = new hxasm.Output();
  hxasm.Writer.write(o,ctx);
  var swf = o.getBytes();

  loader = new flash.display.Loader();
  loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE,onLoaded);
  loader.loadBytes(swf);
    }

    public static function onLoaded(e) {
 var m = loader.contentLoaderInfo.applicationDomain.getDefinition("Main");
 var inst : Dynamic = Type.createInstance(m,[]);
 trace(inst.fib(30));
    }
 
}

之后就一大堆的API

有兴趣的去优化吧,最后做成swf就好了,o(∩_∩)o...哈哈

好啦,翻译到此结束!

Good Luck & Have Fun

About this Archive

This page is an archive of recent entries in the Haxe category.

game is the previous category.

java is the next category.

Find recent content on the main index or look in the archives to find all content.

3D Live Statistics