Sunday, November 13, 2011

HTML5 + Javascript

few lessons learnt:
  1. <script /> is not valid. must use closing tag </script>
  2. made a simple mistake and debug like crazy:
    canvas = document.getElementById("test");
    context = canvas.getContext("2d");
    context.fillStyle("#FF0000"); //SHOULD have been context.fillStyle = "#FF0000";
    context.fillRect( 10, 20, 100, 50);

    More canvas reference: http://www.w3schools.com/html5/html5_ref_canvas.asp
  3. must use addEventListener for mouse input: canvas.addEventListener("mousedown", mDown, false);
  4. cannot get mouse (x,y) relative to canvas top left (0,0) so must manually calculate:
    var mouseX = (e.pageX -canvas.offsetLeft );
    var mouseY = (e.pageY -canvas.offsetTop);
  5. OOP
    function A() // create a class
    {
    this.v = 1; // fields or variables
    this.name = "haha";
    }
    A.prototype.constructor = A;
    A.prototype.m1 = function(){ // methods
    this.v++;
    }
    A.prototype.m2 = function(){
    this.v+=10;
    }
    // new class
B.prototype = new A();
B.prototype.constructor = B;

function B(){

  A.call(this); // call super class constructor if necessary

  this.x = 2;
}
B.prototype.m2 = function()
{
  A.prototype.m2.call(this); // call super class method if necessary
  // do additional stuff
}

var b = new B(); // create instance. BUT instantiation MUST be after the class declaration. debugged for a long time.

Tuesday, October 18, 2011

Flash player 11 + Flash builder 4.5 + Flash CS5

Finally managed to get flash builder 4.5 to publish SWF for flash player 11. 
specifically using Stage3D
  1. Download the PlayerGlobal SWC and debugger player from http://www.adobe.com/support/flashplayer/downloads.html
  2. go to flash builder installation path: "Adobe Flash Builder 4.5\sdks\4.5.1\frameworks\libs\player"
  3. create a new folder "11.0"
  4. copy the SWC into this folder. 
  5. install the debugger player for your browser
  6. Create a new ActionScript project
  7. Go to project properties > Flash Player version > 11.0.0
  8. Add "-swf-version=13" under Compiler Arguments
  9. Add code. eg.: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display3D/Context3D.html#drawTriangles() 
  10. Run the application. 
should work now.

for Flash CS5
  1. Do the same as above for step 1
  2. go to flash cs5 installation path: "\Adobe Flash CS5\Common\Configuration\ActionScript 3.0"
  3. create a new folder "FP11"
  4. copy the SWC into this new folder
  5. go to: "Adobe Flash CS5\Common\Configuration\Players" folder
  6. copy the old "FlashPlayer10_1.xml" to paste as a new "FlashPlayer11.xml"
  7. Edit the XML using NotePad
    Change the following:
    'player id="FlashPlayer11" version="13" asversion="3"'
    '<name>Flash Player 11</name>'
    'as3="$(AppConfig)/ActionScript 3.0/FP11/playerglobal.swc" '
  8. Save and close the XML. 
  9. Go to folder: "Adobe Flash CS5\Players\Debug"
  10. copy the debugger EXE into this folder. change the original FlashPlayerDebugger.exe to  FlashPlayerDebugger_OLD.exe and change the name of the copied EXE to  FlashPlayerDebugger.exe 
  11. Close Flash CS5 and restart. 
  12. Create a new Actionscript 3 FLA.
  13. In Profiles > Version > Flash Player 11
  14. Change rendering to "Direct"
  15. Run the movie by using the Debug movie. Ctrl+shift+enter

Monday, August 22, 2011

Android phone: cannot send sms & make outgoing call

What an experience i have with an Android phone. Samsung Nexus S in particular.
1) cannot charge to 100%. had switched batt and sent to change motherboard. known problem in forums
2) found out later that this is different from Google Nexus S with AMOLED display
3) battery drains pretty fast, comparing to previous experience with iPhone 3G
4) recent encounters: SMS cannot be sent out and cannot make outgoing call when 3G data network is switched on. when switched to GPRS, it's ok. changed SIM card, sent phone for change of motherboard, still same problem. finally saw one suggestion in forums, clear data for the stock "Dialler" and "Messaging" apps. been working well so far.
Steps: Settings > Applications > Manage applications > All > "Dialler" AND "Messaging" > Clear Data

Afternote: the above does not solve the problem with 3G and SMS and voice calls (item 4). in the end, have to wait til M1 and Samsung to resolve this issue from their side. I'm just glad this saga is over and hope that it is the last of this phone. enough of bad experience.

Wednesday, May 11, 2011

BitmapData: histogram

public function histogram(hRect:Rectangle = null):Vector.<Vector.<Number>>

Computes a 256-value binary number histogram of a BitmapData object. This method returns a Vector object containing four Vector. instances (four Vector objects that contain Number objects). The four Vector instances represent the red, green, blue and alpha components in order. Each Vector instance contains 256 values that represent the population count of an individual component value, from 0 to 255.

var hist:Vector.<Vector.<Number>> = bmpData.histogram();
// RGBA order
hist[0][9] = number of pixels having the red color component 9. eg.: 0x093366
total of hist[0][0-255] = total number of pixels in hRect region of bmpData.

flash + webcam + color tracking

Created pixel bender shaders to convert RGB to HSV
Used probability densities to back project histogram
using camshift algorithm

http://psalmhundred.net/experiment/webcam/webcam_demo_color_detect.html

Wednesday, April 06, 2011

Android AVD error

after installing eclipse, JDK, ADT, created AVD
created project
run and experience the following error

emulator: ERROR: unknown virtual device name

gotta add environment variable "ANDROID_SDK_HOME"
and set it to "D:\Users\{username}"
or where the ".android" is.

restart eclipse
and run again.
should be ok now.

Friday, March 11, 2011

render 2011: ddm & dmat graduation show





finally website done (Oct 2010 - Mar 2011). for Dip in Digital Media & Dip in Music and Audio Tech
www.render.sg

mobile site: http://2011.render.sg


Thanks to the following DDM IA students:
Shihui (actionscript), Meixian (backend), Bryan (flash), Mira (design)

& colleagues: Leon Lim (music), Leon Chua (graphic)

Monday, February 07, 2011

Ctrl Fre@k website completed on 5 Jan

finally finished the website on 5 Jan. Used wordpress and customised the theme for Ctrl Fre@k.
Visit Ctrl Fre@k at http://ctrlfreak.sg