Archive for August, 2006

hand/pointer cursor

August 28, 2006

a, a:hover, td a:hover{
cursor: pointer;
cursor: hand;
}

or in js:
div.style.cursor=”pointer”;//for Firefox
div.style.cursor=”hand”;//for IE

Initializing Array inside class in AS2

August 26, 2006

This is a bug in AS2, as I found out. Read the follow-up below.

In most situations (although I haven’t figure out in which situations), as a member of a class, instance variables that are type of array needs to be declared either in the constructor or in other methods of the class, instead of being constructed in the instance variable declaration.

So instead of doing:

class SlideTray extends UIComponent{

__inSlidesArray:Array = new Array();

}

We need to say:

class SlideTray extends UIComponent{

var __inSlidesArray:Array;

function SlideTray(){

__inSlidesArray = new Array();

}

}

This way, whenever a new instance of SlideTray is created, a fresh empty, new __inSlidesArray array is created. Otherwise, if an array instance is instantiated using instance “var __inSlidesArray :Array=new Array();” statement and if a second instance of SlideTray is created after the first one, its __inSlidesArray will “inherit” the value of the first one!

It’s a surprising discovery that took me about 2 hours to figure out.

My experiment is as follows:

//test class

class TestArray{

//purposefully declare the array before the constructor

var __TA:Array = new Array();

var __NUM:Numer = 7;

function TestArray(){

trace(“number is “+__NUM.toString());

}

public function addItem(o:Object):Void{

__TA.push(o);

}

public function addNum(v:Number):Void{

__NUM += v;

}

public function toString():String{

var arr:String = “array: ” +__TA.toString();

var num:String = “number: “+__NUM.toString();

var info:String = arr+” || “+num;

}

}

//main app

var testArray:TestArray = new TestArray();

testArray.addItem(“haha”);

testArray.addItem(233);

testArray.addNum(12);

//output: ‘array: haha,233 || number: 12’;

trace(“testArray: “+testArray.toString());

var testArray2:TestArray = new TestArray();

//output: ‘array: haha, 233 || number: 7’;

trace(testArray2.toString());

The point is that the array in the newly created object, if created the way as described above, will remain as the same value as that of the last created instance. Debugging work like this will generally take 0.5 – 2 – 4 hours.

So the right way is  to create arrays inside methods/class constructors instead of in instance variable statements.

FOLLOW-UP:

Today for some reason I revisited the post and ran some tests on FB3/AS3, and it turned out it all looked normal in ActionScript 3. For a non-static (non-primitive or primitive) variable (I tested on a data type of Array and Person(name:String, sex:String, age:Number), you can initialize it either in constructor or when you declare the variable. The instance of the class should retain a unique reference to the variable. Of course this is another story for a static variable, which always has one copy in the memory. For the basics of stuff, read "Member Initialization" (p191) on Chapter 4: Initialization & Cleanup of Thinking in Java  3rd Ed by Bruce Eckel.

In AS3, the only difference between initializing a variable inside a method vs. initializing it when you define the variable within a class, is the order of initialization. The compiler initializes variables first before any metod calls - even before the constructor, in the order they are defiend in the class. So if you choose to initialize a variable inside the constructor, it will be initialized twice: once set to its default value when it's defined, and reinitialized within the method.

In AS2, it seems you can only initialize primitives and Arrays; if you try to initialize a class when you define the class variable, you would get an error saying "A class's instance variables may only be initialized to compile-time constant expressions." The comiler will fail at the point of the variable definition. The bug comes when you try to initialize an Array as class variable definition. Flash does it as if you were doing a static var, even if what you are trying to declare is a non-static one, as described above in this post.

loading another iframe from the parent

August 25, 2006

to refer to the parent from within iframe:

var parent = window.parent;

to  refert to the iframe from within the parent:

var iframe= window.all.iframeEl;

//the url of the iframe
var url = iframe.src

Flash object background

August 25, 2006

if wmode of the flash object property is “opaque”, the
bgcolor property also needs to be explicitly set in the form of hexadecimals.

If the flash object resides in a table, the table’s (or the table cell /td) bgcolor also needs to be set.

background-image url in css

August 24, 2006

the url in the background/background-image rule is relative to the css file. E.i.,

background:url(../img/delete.gif) no-repeat top left;

The above css file is in folder “css” which is the same level as “img” where the gif is in.

Basic mySQL commands

August 22, 2006

Establishing a DB connection, with PHP

1. mysql_connect()

2. mysql_select_db()

3. mysql_query()

4. mysql_fetch_array()

5. mysql_result()

6. mysql_error()

Basic SQL commands

CREATE TABLE

ALTER TABLE CHANGE/ADD/DROP

DROP TABLE

INSERT INTO ( , , , … ) VALUES ( , , , …);

UPDATE WHERE

SELECT FROM WHERE WHERE/GROUP BY/HAVING/ORDER BY LIMIT…

DELETE FROM WHERE

javascript list object

August 22, 2006

I got two quick and dirty ways to build a list/array type of object in js:

1. javascript object literals

2. javascript array literals

In the first way, to build a javascript object literal: var listObj = new Object();

To extend the list, you don’t need to call any methods in javascript object, instead simply do: listObj[“id4″] = {name:”tsi chuan”, phone:”312-222-222″};

It’s not easy to figure out how many objects are within the current list.

In the second way,

var listArr = new Array();

listArr[0] = {name:”tsi chuan”, phone:”312-222-222″};

listArr[2] = {name:”tsi chuan NEW”, phone:”312-222-333″};
//listArr.length will be 3.
It’s easy to sort the array list by index number and to figure out how many objects are really inside the list, like so:

if(listArr[2][“name”]!=undefined){//the obj exists.}

Since we are not using any methods on the objects, there is no way to keep track of the length property of the array object once this approach is used.

tbody scroll for IE

August 20, 2006

by ofir

http://www.webdeveloper.com/forum/showthread.php?t=92584

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<
head>
<
meta httpequiv=“content-type” content=“text/html; charset=iso-8859-1” />
<
title>website</title>
<
style type=‘text/css’>
body{
padding:0;
margin: 20px;
font: normal 13px arial, sansserif;
}

table.TableMain{
border: 1px solid black;
}

thead tr th, tfoot tr th{
backgroundcolor: #996600;
}

.scrollTable th, .scrollTable td{
padding: 5px;
border: solid black;
borderwidth: 0 1px 1px 0;
}

.scrollTable{ width:100% }

.scrollTable > tbody{
height:300px;
overflow:auto;
}

.scrollTable .th_extra{
width: 18px;
padding: 0;
borderrightwidth: 0;
}

.TableContainer > .scrollTable .th_extra{ width: 19px; }

</style>
<!–[if
IE]>
<
style type=“text/css”>
div.TableContainer {
height: 300px;
overflow: auto;
width: 100%;
}

thead.fixedHeader tr {
position: relative;
}
.
scrollTable{width: expression(this.parentNode.offsetWidth17);}
.
th_extra{display:none;}
</
style>
<![endif]–>

</head>

<body>

<table border=‘0’ cellspacing=‘0’ cellpadding=‘0’ class=‘TableMain’ width=‘60%’>
<
tr>
<
td>
<
div class=“TableContainer”>
<
table border=‘0’ cellspacing=‘0’ cellpadding=‘0’ class=“scrollTable”>
<
thead class=“fixedHeader”>
<
tr>
<
th>wkdjchlkj</th>
<
th>khwdgc9376</th>
<
th>76235uyg</th>
<
th>yg</th>
<
th class=‘th_extra’></th>
</
tr>
</
thead>
<
tfoot>
<
tr>
<
th>wkdjchlkj</th>
<
th>khwdgc9376</th>
<
th>76235uyg</th>
<
th>7</th>
<
th class=‘th_extra’></th>
</
tr>
</
tfoot>
<
tbody class=“scrollContent”>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
<
tr>
<
td>1111111111</td>
<
td>JAh RAsta</td>
<
td>222</td>
<
td>444444444444</td>
</
tr>
</
tbody>
</
table>
</
div>

</td>
</
tr>
</
table>

</body>
</
html>

Make a CSS inpage “popup”

August 18, 2006

To make a CSS “popup” such as those for “login”, you need two divs:

one is semitransparent and one is not,with the latter sitting on top of the former. Like so:

#semitranslayer {
		display: none;
		position: absolute;
		top: 45px;
		left: 0;
		margin: 0 0 -1500px;
		height: 1px;
		font-size: 0;
		width: 100%;
		height: 100%;
		background: #042f51;
		z-index: 10050;
		opacity: .7;
		filter: progid:DXImageTransform.Microsoft.Alpha(opacity=70);
	}

Keep Flash object underneath other divs

August 18, 2006

Use the following properties for Flash object, as well as set z-index rule for the Flash div to lower number (like 0):

<param name="wmode" value="opaque" />
<embed wmode="opaque" />