RSS
 

Archive for February, 2011

learning Red5 and Java.

05 Feb

yea it’s been long i visited my own blog.

All thanks to the series of events i have been experiencing from the 10th of September 2010. I was robbed and lost a 2009 Toyota sienna.  Sorry i didn’t configure an event listener so you didn’t know .

Yea, this.addEventListener(MouseEvent.CLICK, boom);

That’s one of the stuffs am getting addicted to everyday. I had to put PHP aside and pick up java and actionscript

I need both languages for my new project.

It has been a tough curve learning Red5/ Java and understanding AS3.  I will start posting stuffs here as i learn them.

the way i learn is by doing it, getting it wrong, and discovering why i got it wrong. That way, it stick forever.

one quick tip for red5 developers, i set up this .bat file i put on my taskbar.

once am done in netbeans, i hit the compile button, next hit the .bat file on my shortcut. The .bat file fires up the cmd prompt window and says stuff like

that simple copies the .jar file to my red5 webapps folder ,

stop red5, then start it.

Next to it i also have a log.txt shortcut to my red5 installation directory.

I had to come up with my custom log file since red5 log… well, it really doesnt ‘work on my system. so the trick is to have a method in my java that read like so:

public static void error(String err){
try{
// Create file
FileWriter fstream = new FileWriter(“error.txt”,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(err+”—\n”);
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
error(“Error: ” + e.getMessage());
}
}

so it just writes the error to a file and it’s easier having all your tools in one place.

Next to that shortcut, i have another shortcut to a small program i wrote using C++,

…well i copied it from somewhere on the web, tweaked it to my taste and renamed it mine.

it does exactly what my mozilla firefox does, just that the swf debugger in my firefox sometimes decide to go nuts

so i came up with this, the debugger shows up too but better cos it never hangs and testing my apps just got easier. I am going to share the C++ code with you. incase u find errors in the code, notify me, i really dont do C++, it’s very very boring.

#define _WIN32_WINNT 0x0500
#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

const char g_szClassName[] = “myWindowClass”;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE prev,
LPSTR lpCmdLine, int show )
{

FARPROC init = GetProcAddress(LoadLibrary(“atl”),”AtlAxWinInit”);
init();
WNDCLASSEX wc;
HWND hwnd;
MSG msg;

//Step 1: Registering the Window Class
wc.cbSize        = sizeof(WNDCLASSEX);
wc.style         = 0;
wc.lpfnWndProc   = WndProc;
wc.cbClsExtra    = 0;
wc.cbWndExtra    = 0;
wc.hInstance     = prev;
wc.hIcon         = LoadIcon(hInstance,(LPCTSTR)IDI_APPLICATION);
wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName  = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm       = LoadIcon(hInstance,(LPCTSTR)IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, “Window Registration Failed!”, “Error!”,
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
“Kilonsele | Very Addictive…”,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 1019, 620,NULL, NULL, prev, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, “Window Creation Failed!”, “Error!”,
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

CreateWindow(“AtlAxWin”, “http://localhost/main.swf”,
WS_VISIBLE|WS_CHILDWINDOW,0,0,1000,600,hwnd,0,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),0);

ShowWindow(hwnd, show);
UpdateWindow(hwnd);

while( GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

switch(msg)
{

case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}