on i4PACE(i for Personal Archiving and Creating Environment)
actions » SearchLogin 89 articles • 30 Jul 2010

Recent articles in 'haxe'

Tuesday, 09 Sep 2008

permalink haxeVideo

haXe has a library called haxeVideo to play flash video streams. Here's a memo to install and play a demo video.

http://code.google.com/p/haxevideo/wiki/Help gives instructions, but its link to the download site is incorrect. http://haxevideo.org/ is the site for downloading haxevideo-1.1.zip. Install haxe's format library for compiling haxevideo:

$ haxelib install format

Unzip the file, and

$ cd haxevideo-1.1
$ haxe video.hxml

which creates video.swf and server.n. Run nekoVM server by

$ neko server.n localhost

will run RTMP server at port 1935 by default. Run Apache2 and point to the directory the server is in, and then http://localhost/video.html on a browser shows the page for video. [[image: haxevideo.png]] It worked ! Great :->

• Wrote Teru at 18:59 | read 112× | 0 Comments

Saturday, 06 Sep 2008

permalink haXe

Found haXe at http://haxe.org interesting. Here's my first try to use it. Access to http://haxe.org/, hit "Download", then "Download linux installer". Untarring the file hxinst-linux.tgz creates an executable hxinst-linux. Open a terminal and do

sudo hxinst-linux

The monitor then looks like [[image: haxe.png]] Hit "はい"(y), installation starts, and finishes [[image: haxe1.png]] Here's the log shown in the window:

No proxy found
Getting Local haXe Version
Getting Local Neko Version
Getting Latest haXe Version
Getting Latest Neko Version
Downloading neko-1.7.1-linux.tar.gz (100%)
Downloading haxe-2.0-linux.tar.gz (100%)
Installing directory include
Execute rm -rf /usr/bin/neko
Execute ln -s /usr/lib/neko/neko /usr/bin/neko
Execute rm -rf /usr/bin/nekoc
Execute ln -s /usr/lib/neko/nekoc /usr/bin/nekoc
Execute rm -rf /usr/bin/nekotools
Execute ln -s /usr/lib/neko/nekotools /usr/bin/nekotools
Execute rm -rf /usr/lib/libneko.so
Execute ln -s /usr/lib/neko/libneko.so /usr/lib/libneko.so
Installing directory doc
Installing directory doc/content
Installing directory doc/content/flash
Installing directory doc/content/flash/_MovieClip
Installing directory doc/content/flash/display
Installing directory doc/content/flash/external
Installing directory doc/content/flash/filters
Installing directory doc/content/flash/geom
Installing directory doc/content/flash/net
Installing directory doc/content/flash/system
Installing directory doc/content/flash/text
Installing directory doc/content/flash9
Installing directory doc/content/flash9/accessibility
Installing directory doc/content/flash9/display
Installing directory doc/content/flash9/errors
Installing directory doc/content/flash9/events
Installing directory doc/content/flash9/external
Installing directory doc/content/flash9/filters
Installing directory doc/content/flash9/geom
Installing directory doc/content/flash9/media
Installing directory doc/content/flash9/net
Installing directory doc/content/flash9/printing
Installing directory doc/content/flash9/sampler
Installing directory doc/content/flash9/system
Installing directory doc/content/flash9/text
Installing directory doc/content/flash9/text/engine
Installing directory doc/content/flash9/trace
Installing directory doc/content/flash9/ui
Installing directory doc/content/flash9/utils
Installing directory doc/content/flash9/xml
Installing directory doc/content/haxe
Installing directory doc/content/haxe/_Http
Installing directory doc/content/haxe/_Template
Installing directory doc/content/haxe/io
Installing directory doc/content/haxe/remoting
Installing directory doc/content/haxe/rtti
Installing directory doc/content/haxe/unit
Installing directory doc/content/haxe/xml
Installing directory doc/content/haxe/xml/_Check
Installing directory doc/content/haxe/xml/_Fast
Installing directory doc/content/js
Installing directory doc/content/neko
Installing directory doc/content/neko/db
Installing directory doc/content/neko/db/_Mysql
Installing directory doc/content/neko/db/_Sqlite
Installing directory doc/content/neko/io
Installing directory doc/content/neko/io/_Process
Installing directory doc/content/neko/net
Installing directory doc/content/neko/net/_ServerLoop
Installing directory doc/content/neko/net/_ThreadServer
Installing directory doc/content/neko/vm
Installing directory doc/content/neko/zip
Installing directory doc/content/php
Installing directory doc/content/php/db
Installing directory doc/content/php/db/_DBase
Installing directory doc/content/php/db/_Mysql
Installing directory doc/content/php/db/_Sqlite
Installing directory doc/content/php/io
Installing directory doc/content/php/io/_Process
Installing directory doc/content/php/net
Installing directory doc/content/tools
Installing directory doc/content/tools/haxedoc
Installing directory doc/content/tools/haxelib
Installing directory doc/content/tools/hxinst
Installing directory std
Installing directory std/flash
Installing directory std/flash/display
Installing directory std/flash/external
Installing directory std/flash/filters
Installing directory std/flash/geom
Installing directory std/flash/net
Installing directory std/flash/system
Installing directory std/flash/text
Installing directory std/flash9
Installing directory std/flash9/display
Installing directory std/flash9/accessibility
Installing directory std/flash9/events
Installing directory std/flash9/external
Installing directory std/flash9/filters
Installing directory std/flash9/geom
Installing directory std/flash9/media
Installing directory std/flash9/net
Installing directory std/flash9/printing
Installing directory std/flash9/system
Installing directory std/flash9/text
Installing directory std/flash9/text/engine
Installing directory std/flash9/ui
Installing directory std/flash9/utils
Installing directory std/flash9/xml
Installing directory std/flash9/errors
Installing directory std/flash9/sampler
Installing directory std/flash9/trace
Installing directory std/haxe
Installing directory std/haxe/remoting
Installing directory std/haxe/rtti
Installing directory std/haxe/unit
Installing directory std/haxe/xml
Installing directory std/haxe/io
Installing directory std/js
Installing directory std/neko
Installing directory std/neko/db
Installing directory std/neko/io
Installing directory std/neko/net
Installing directory std/neko/vm
Installing directory std/neko/zip
Installing directory std/tools
Installing directory std/tools/haxedoc
Installing directory std/tools/haxelib
Installing directory std/tools/hxinst
Installing directory std/php
Installing directory std/php/db
Installing directory std/php/io
Installing directory std/php/net
Execute rm -rf /usr/bin/haxe
Execute ln -s /usr/lib/haxe/haxe /usr/bin/haxe
Execute rm -rf /usr/bin/haxelib
Execute ln -s /usr/lib/haxe/haxelib /usr/bin/haxelib
Execute rm -rf /usr/bin/haxedoc
Execute ln -s /usr/lib/haxe/haxedoc /usr/bin/haxedoc
Installation Completed

Now, at http://haxe.org/doc, hit "Getting started with haXe/JS" and try the example there. Create Test.hx which has

class Test {
    static function main() {
        trace("Hello World !");
    }
}

Create compile.hxml in the same directory which has

-js test.js
-main Test

Running

haxe compile.hxml

, creates test.js, which has

$estr = function() { return js.Boot.__string_rec(this,''); }
Std = function() { }
Std.__name__ = ["Std"];
Std["is"] = function(v,t) {
	return js.Boot.__instanceof(v,t);
}
Std.string = function(s) {
	return js.Boot.__string_rec(s,"");
}
Std["int"] = function(x) {
	if(x < 0) return Math.ceil(x);
	return Math.floor(x);
}
Std.parseInt = function(x) {
	var v = parseInt(x);
	if(Math.isNaN(v)) return null;
	return v;
}
Std.parseFloat = function(x) {
	return parseFloat(x);
}
Std.random = function(x) {
	return Math.floor(Math.random() * x);
}
Std.prototype.__class__ = Std;
IntIter = function(min,max) { if( min === $_ ) return; {
	this.min = min;
	this.max = max;
}}
IntIter.__name__ = ["IntIter"];
IntIter.prototype.hasNext = function() {
	return this.min < this.max;
}
IntIter.prototype.max = null;
IntIter.prototype.min = null;
IntIter.prototype.next = function() {
	return this.min++;
}
IntIter.prototype.__class__ = IntIter;
haxe = {}
haxe.Log = function() { }
haxe.Log.__name__ = ["haxe","Log"];
haxe.Log.trace = function(v,infos) {
	js.Boot.__trace(v,infos);
}
haxe.Log.clear = function() {
	js.Boot.__clear_trace();
}
haxe.Log.prototype.__class__ = haxe.Log;
Test = function() { }
Test.__name__ = ["Test"];
Test.main = function() {
	haxe.Log.trace("Hello World !",{ fileName : "Test.hx", lineNumber : 3, className : "Test", methodName : "main"});
}
Test.prototype.__class__ = Test;
js = {}
js.Lib = function() { }
js.Lib.__name__ = ["js","Lib"];
js.Lib.isIE = null;
js.Lib.isOpera = null;
js.Lib.alert = function(v) {
	alert(js.Boot.__string_rec(v,""));
}
js.Lib.eval = function(code) {
	return eval(code);
}
js.Lib.setErrorHandler = function(f) {
	js.Lib.onerror = f;
}
js.Lib.prototype.__class__ = js.Lib;
js.Boot = function() { }
js.Boot.__name__ = ["js","Boot"];
js.Boot.__unhtml = function(s) {
	return s.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
}
js.Boot.__trace = function(v,i) {
	var msg = (i != null?i.fileName + ":" + i.lineNumber + ": ":"");
	msg += js.Boot.__unhtml(js.Boot.__string_rec(v,"")) + "<br/>";
	var d = document.getElementById("haxe:trace");
	if(d == null) alert("No haxe:trace element defined\n" + msg);
	else d.innerHTML += msg;
}
js.Boot.__clear_trace = function() {
	var d = document.getElementById("haxe:trace");
	if(d != null) d.innerHTML = "";
	else null;
}
js.Boot.__closure = function(o,f) {
	var m = o[f];
	if(m == null) return null;
	var f1 = function() {
		return m.apply(o,arguments);
	}
	f1.scope = o;
	f1.method = m;
	return f1;
}
js.Boot.__string_rec = function(o,s) {
	if(o == null) return "null";
	if(s.length >= 5) return "<...>";
	var t = typeof(o);
	if(t == "function" && (o.__name__ != null || o.__ename__ != null)) t = "object";
	switch(t) {
	case "object":{
		if(o instanceof Array) {
			if(o.__enum__ != null) {
				if(o.length == 2) return o[0];
				var str = o[0] + "(";
				s += "\t";
				{
					var _g1 = 2, _g = o.length;
					while(_g1 < _g) {
						var i = _g1++;
						if(i != 2) str += "," + js.Boot.__string_rec(o[i],s);
						else str += js.Boot.__string_rec(o[i],s);
					}
				}
				return str + ")";
			}
			var l = o.length;
			var i;
			var str = "[";
			s += "\t";
			{
				var _g = 0;
				while(_g < l) {
					var i1 = _g++;
					str += ((i1 > 0?",":"")) + js.Boot.__string_rec(o[i1],s);
				}
			}
			str += "]";
			return str;
		}
		var tostr;
		try {
			tostr = o.toString;
		}
		catch( $e0 ) {
			{
				var e = $e0;
				{
					return "???";
				}
			}
		}
		if(tostr != null && tostr != Object.toString) {
			var s2 = o.toString();
			if(s2 != "[object Object]") return s2;
		}
		var k = null;
		var str = "{\n";
		s += "\t";
		var hasp = (o.hasOwnProperty != null);
		for( var k in o ) { ;
		if(hasp && !o.hasOwnProperty(k)) continue;
		if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__") continue;
		if(str.length != 2) str += ", \n";
		str += s + k + " : " + js.Boot.__string_rec(o[k],s);
		}
		s = s.substring(1);
		str += "\n" + s + "}";
		return str;
	}break;
	case "function":{
		return "<function>";
	}break;
	case "string":{
		return o;
	}break;
	default:{
		return String(o);
	}break;
	}
}
js.Boot.__interfLoop = function(cc,cl) {
	if(cc == null) return false;
	if(cc == cl) return true;
	var intf = cc.__interfaces__;
	if(intf != null) {
		var _g1 = 0, _g = intf.length;
		while(_g1 < _g) {
			var i = _g1++;
			var i1 = intf[i];
			if(i1 == cl || js.Boot.__interfLoop(i1,cl)) return true;
		}
	}
	return js.Boot.__interfLoop(cc.__super__,cl);
}
js.Boot.__instanceof = function(o,cl) {
	try {
		if(o instanceof cl) {
			if(cl == Array) return (o.__enum__ == null);
			return true;
		}
		if(js.Boot.__interfLoop(o.__class__,cl)) return true;
	}
	catch( $e1 ) {
		{
			var e = $e1;
			{
				if(cl == null) return false;
			}
		}
	}
	switch(cl) {
	case Int:{
		return Math.ceil(o) === o && isFinite(o);
	}break;
	case Float:{
		return typeof(o) == "number";
	}break;
	case Bool:{
		return o === true || o === false;
	}break;
	case String:{
		return typeof(o) == "string";
	}break;
	case Dynamic:{
		return true;
	}break;
	default:{
		if(o == null) return false;
		return o.__enum__ == cl || (cl == Class && o.__name__ != null) || (cl == Enum && o.__ename__ != null);
	}break;
	}
}
js.Boot.__init = function() {
	js.Lib.isIE = (document.all != null && window.opera == null);
	js.Lib.isOpera = (window.opera != null);
	Array.prototype.copy = Array.prototype.slice;
	Array.prototype.insert = function(i,x) {
		this.splice(i,0,x);
	}
	Array.prototype.remove = function(obj) {
		var i = 0;
		var l = this.length;
		while(i < l) {
			if(this[i] == obj) {
				this.splice(i,1);
				return true;
			}
			i++;
		}
		return false;
	}
	Array.prototype.iterator = function() {
		return { cur : 0, arr : this, hasNext : function() {
			return this.cur < this.arr.length;
		}, next : function() {
			return this.arr[this.cur++];
		}}
	}
	var cca = String.prototype.charCodeAt;
	String.prototype.cca = cca;
	String.prototype.charCodeAt = function(i) {
		var x = cca.call(this,i);
		if(isNaN(x)) return null;
		return x;
	}
	var oldsub = String.prototype.substr;
	String.prototype.substr = function(pos,len) {
		if(pos != null && pos != 0 && len != null && len < 0) return "";
		if(len == null) len = this.length;
		if(pos < 0) {
			pos = this.length + pos;
			if(pos < 0) pos = 0;
		}
		else if(len < 0) {
			len = this.length + len - pos;
		}
		return oldsub.apply(this,[pos,len]);
	}
	$closure = js.Boot.__closure;
}
js.Boot.prototype.__class__ = js.Boot;
$Main = function() { }
$Main.__name__ = ["@Main"];
$Main.prototype.__class__ = $Main;
$_ = {}
js.Boot.__res = {}
js.Boot.__init();
{
	String.prototype.__class__ = String;
	String.__name__ = ["String"];
	Array.prototype.__class__ = Array;
	Array.__name__ = ["Array"];
	Int = { __name__ : ["Int"]}
	Dynamic = { __name__ : ["Dynamic"]}
	Float = Number;
	Float.__name__ = ["Float"];
	Bool = { __ename__ : ["Bool"]}
	Class = { __name__ : ["Class"]}
	Enum = { }
	Void = { __ename__ : ["Void"]}
}
{
	Math.NaN = Number["NaN"];
	Math.NEGATIVE_INFINITY = Number["NEGATIVE_INFINITY"];
	Math.POSITIVE_INFINITY = Number["POSITIVE_INFINITY"];
	Math.isFinite = function(i) {
		return isFinite(i);
	}
	Math.isNaN = function(i) {
		return isNaN(i);
	}
	Math.__name__ = ["Math"];
}
{
	onerror = function(msg,url,line) {
		var f = js.Lib.onerror;
		if( f == null )
			return false;
		return f(msg,[url+":"+line]);
	}
}
js.Lib.document = document;
js.Lib.window = window;
js.Lib.onerror = null;
$Main.init = Test.main();

Wow, that's quite long for a simple program for showing hello world %-| Actually, what's directly relevant was the following lines:

Test = function() { }
Test.__name__ = ["Test"];
Test.main = function() {
	haxe.Log.trace("Hello World !",{ fileName : "Test.hx", lineNumber : 3, className : "Test", methodName : "main"});
}

Create test.html as

<html>
<head><title>haXe JS</title></head>
<body>

<div id="haxe:trace"></div>
<script type="text/javascript" src="test.js"></script>

</body>
</html>

which shows on a browser like [[image: haxe2.png]] which looks quite humbling in expression, but it works :-) Now, how about flash? Change the compile.hxml to

-swf test.swf
-main Test

Recompiling by

haxe compile.hxml

creates test.swf. Change test.html to

<html>
<head><title>haXe Flash</title></head>
<body bgcolor="#dddddd">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
        width="400"
    height="300"
    id="haxe"
    align="middle">
<param name="movie" value="test.swf"/>
<param name="allowScriptAccess" value="always" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="salign" value="lt" />
<param name="bgcolor" value="#ffffff"/>
<embed src="test.swf"
       bgcolor="#ffffff"
       width="400"
       height="300"
       name="haxe"
       quality="high"
       align="middle"
       allowScriptAccess="always"
       type="application/x-shockwave-flash"
       pluginspage="http://www.macromedia.com/go/getflashplayer"
/>
</object>
</body>
</html>

and show on a browser [[image: haxe3.png]] Modifying Test.hx to

class Test {
    static function main() {
        var mc : flash.MovieClip = flash.Lib.current;
        mc.beginFill(0xFF0000);
        mc.moveTo(50,50);
        mc.lineTo(100,50);
        mc.lineTo(100,100);
        mc.lineTo(50,100);
        mc.endFill();
    }
}

will draw a square on a screen. A program called swfmill is recommended to creaste a swf file. installed swfmill using Synaptic. As an example, create a file foo.xml like

<?xml version="1.0" encoding="utf-8" ?>
	
<movie width="640" height="480" framerate="12">
  <background color="#ffffff"/>
  <frame>
    <library>
      <clip id="foo" import="library/pic.png"/>
    </library>
  </frame>
</movie>

and ran

swfmill simple foo.xml bar.swf

Change Test.hx to

class Test {
    static function main() {
         var but = flash.Lib.current.attachMovie("foo", "pic001", 0);
         but._x = 10;
         but._y = 20;
    }
}


and compile.hxml to

-swf test.swf
-swf-lib bar.swf
-main Test


Ran

haxe compile.hxml

and test.html on a browser looks like [[image: haxe4.png]] where the parameters for size were changed to cover the picture size.

• Wrote Teru at 22:26 | read 50× | 0 Comments

2 shown; more articles may be found in the archives. The permalink icon is the article's permalink.
Process times: page=0.378 request=0.402 cpu=0.400