Wednesday, November 26, 2008

Sunday, November 16, 2008

Flash AS3 Custom Component - parameters

If the parameters are modified during authoring time,
they are not ready til after the constructor is called.


package{
import flash.display.*;
import flash.events.*;
import flash.net.*;
public class Testing extends MovieClip{
[Inspectable]
public var id:Number = 0;
function Testing(){
this.addEventListener(MouseEvent.CLICK, mouseclick);
}
function mouseclick(e:MouseEvent):void{
trace("id" + id);
}
}
}

Tuesday, August 12, 2008

Elastic Flash Demo

Key in a number from 2-20 in the textbox and click the button to generate an elastic object. Use the mouse to drag the dots.

Tuesday, July 08, 2008

Microsoft.Win32.OpenFileDialog affect FileIO operation

Just found out that if I use the following code to retrieve a filename, the FileStream will be affected as the current directory will be set to where the filename was taken from, eg.: "My Documents", instead of the Application Path.

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "All files (*.*)|*.*";
if ((bool)dialog.ShowDialog())
{
// store filename
}

// and later in the code
FileStream stream = new FileStream(
"mydata.bin", FileMode.Create);
BinaryWriter writer = new BinaryWriter(stream);
// write some data
stream.Close();
// "mydata.bin" will be saved in the current directory of OpenFileDialog

One solution will be to use the application path and extract the directory:
String path = System.Reflection.Assembly.GetExecutingAssembly().Location;

another will be to use RestoreDirectory property of the OpenFileDialog. set it to true.

Thursday, June 19, 2008

Flash 10 3D Demo - partial cube

NOT working. Flash 10 player has been updated to official release.

Requires Flash 10 (currently beta)
http://labs.adobe.com/downloads/flashplayer10.html

Demo of rotating cube(partial to see culling effect):
http://psalmhundred.net/experiment/flash3d/Flash10App.html

Flash 10 3D API - Utils3D.projectVectors(...)

Utils3D.projectVectors(m:Matrix3D, verts:Vector, projectedVerts:Vector, uvts:Vector) causes Flash player 10 beta to crash currently.

so just a workaround, a custom method to do similar thing:

public function projectVectors(projMatrix:Matrix3D, vert:Vector.<Number>,
v2D:Vector.<Number>, uvt:Vector.<Number>):void{

var temp:Vector.<Number> = new Vector.<Number>(vert.length);
projMatrix.transformVectors(vert, temp);
var z:Number = 0;
for(var i:int = 0; i<temp.length/3; i++){
z = temp[i*3+2];
z = focalLength / (focalLength+z);
// x' = f*x/(f+z), y' = f*y/(f+z)
v2D[i*2] = temp[i*3]*z;
v2D[i*2+1] = temp[i*3+1]*z;
// t = f/(f+z)
uvt[i*3+2] = z;
}
}