Events and Memory
March 27th, 2008If you have an object a of type A that has a property b of type B:
if you do inside A something like: b.addEventListener(SOME_EVENT, this._handler); …
Later in your code, even if you set b = null and a = null, a and b will still linger in the memory as long as you dont do: b.removeEventListener(SOME_EVENT, this._handler);
TextFieldAutoSize.LEFT and getCharBoundaries
March 4th, 2008If you have a TextField called tf with the following properties:
tf.autoSize = TextFieldAutoSize.LEFT; // or TextFieldAutoSize.Center
tf.width = CONSTANT;
tf.wordWrap = true;
If TextField’s text wraps into multiple lines, doing tf.getCharBoundaries(charIndex), where charIndex is the index of a character in any line but the first, will get you a null instead of a rectangle.
John Neumann (Not the saint one) inheritance
January 30th, 2008Historians recognize John Van Neumann as the genius behind the creation of today’s computer. It was his genius yet simple and clear explanation of the input-process-output scheme that inspired and led engineers and scientists during late 1940s to create the first versions of nowadays’ computers. Neumann’s original idea was that an executable program controls the action of a general-purpose machine.[Video about Neumann ]The complex activities of a computer are only possible through a close interaction of hardware and software. While software is stored in memory, the central processing unit ( CPU ) has the hardware which is actually executes the program instructions.
|
Instructions
→ |
|
Decades after Neumann’s discovery, different chip manufacturers such as IBM, Sun and Intel were created. Unfortunately, they all use different machine instructions. This adds more complexity to low level development. Machine instructions fall into 4 categories:
1- Data transfer and manipulation: AND, OR, ADD, MOV, ADD, MUL.
2- Input and Output: IN and OUT. These instructions handle the transfer of data in and out of the outside world. However some CPU don’t implement this category and handle external data the same way as data coming from the internal memory.
3- Transfer of program control: BRA, JMP, BSR, RTS, GOTO.
4- Machine controls: HALT, etc…
These instructions will get translated into 0s and 1s which is called the Binary code.
Binary numbers are 0s and 1s and is the language computers understand. Humans are used to decimal numbers, and I think it is because we have 10 fingers. Everything that goes into computers gets eventually translated to 0s and 1s.
From Wikipedia.org: To convert from a base-10 integer numeral to its base-2 (binary) equivalent, the number is divided by two, and the remainder is the least-significant bit. The (integer) result is again divided by two, its remainder is the next most significant bit. This process repeats until the result of further division becomes zero.
For example, 11810, in binary, is:
| Operation | Remainder |
|---|---|
| 118 ÷ 2 = 59 | 0 |
| 59 ÷ 2 = 29 | 1 |
| 29 ÷ 2 = 14 | 1 |
| 14 ÷ 2 = 7 | 0 |
| 7 ÷ 2 = 3 | 1 |
| 3 ÷ 2 = 1 | 1 |
| 1 ÷ 2 = 0 | 1 |
Programmers, through the history of computers had to write their programs in binary. But later, they were able to use assemblers – Assembly language. Fortunately, High Level Languages were created and now being used by Software Engineers or I wouldn’t be one.
HLL can be either translated using a compiler or an interpreter. Interpreters are used, aside from reducing development time, to facilitate portability of programs.
For those who have experience with Windows development, they sure heard of DLLs and know what and how they are being used. And for those who don’t: DLL stands for Dynamic Linked Library, which is simply a bunch of routines that can be used with our code if you want to. You can do that by importing and using packages.
There are also static linked libraries, which get privately/solely used by the program that requested them.
When compiling, the compiler does the linking for you.
ActionScript Layout System
January 26th, 2008
Download Layout Package code and documentation
View documentation of the Layout Package
When worked with WPF ( Windows Presentation Foundation ), and after many years in Flash development, I first had a hard time adopting with the concept of layout system. I didn’t like how I wasn’t able to freely place my objects on the stage and make all the updates manually. Then, after messing with the WPF’s StackPanel and Grid, I saw the real need of having a layout system in Flash that will magically restructure it’s tree of children every time one child moves or adjusts any property that affects it’s form. I started my engine with building a StackPanel and WrapPanel, so what are these panels and how do they behave?
Both Stack and Wrap panels extend Panel class that extends UIElement, which inherits Sprite as shown in the figure below:
Sprite
-> UIElement
-> Panel
-> StackPanel , WrapPanel
UIElement: documentation
Extends Sprite and it’s key use consists of the fact it fires an invalidate event every time it moves or changes it’s form and because it uses margins. I used Sprite instead of MovieClips because of the overhead that MovieClip class imposes and since Sprite is the most common used class.
To use the Y! layout engine, you should extend UIElement instead of Sprite and have it as a base class for all your display objects.
Tip:
If your project requires the use of MovieClips and not Sprite, the only modification to the layout package will be modify the code of UIElement and make it extend MovieClip instead of Sprite.
Below is an example of a class named Square that extends UIElement and has a square shape in it’s tree of children.
| import com.yahoo.layout.Panel; import com.yahoo.layout.UIElement; import flash.display.Shape;public class Square extends UIElement {
} |
Panel: documentation
Extends UIElement and every time one of its children is invalidated, it bubbles the invalidation up to its parent and it arranges all its children.
Panel class is the base class for all the existing panels – Stack and Wrap, and the future ones.
WrapPanel: documentation
Places it’s children in sequential position into rows and columns either from left to right or top to bottom depending on the Orientation property.
Below is an Example of Wrap Panel that uses the Square class I wrote previously.
| import com.yahoo.layout.UIElement; import com.yahoo.layout.WrapPanel;public class WrapPanelTest extends Sprite { public function WrapPanelTest()
{
var wrapPanel:WrapPanel = new WrapPanel();
this.addChild(wrapPanel);wrapPanel.width = 300;
wrapPanel.wrap = true;
for(var i:int = 0; i<6; i++)
{
/*Square is custom class that extends UIElement and just
has a square shape in it.*/
var s:Square = new Square();
s.left = s.right = s.top = s.bottom = 5;
wrapPanel.addChild(s);
}
}
} |
Output:
![]()
Tip:
In the Wrap Panel you can specify the number of children in one row or column as well as the orientation to either horizontal or vertical.
If you apply any transformation on any of the children, the Warp Panel will redraw it self according to that transformation. Below is an example where I rotated and skewed one child.
![]()
StackPanel: documentation
Arranges its children into a single line that can be oriented horizontally or vertically depending on the Orientation property.
| import com.yahoo.layout.UIElement; import com.yahoo.layout.StackPanel;public class StackPanelTest extends Sprite {
} |
Output:
![]()
Tip:
In order for you to create a complex layout, you can have Stack Panels and Wrap Panels nested within each other.
Silicon Valley’s Arab Technology Forum 2008
January 22nd, 2008I had the chance to attend the Arab Technology Forum hosted by Techwadi and meet a few Arab entrepreneurs and leaders in the Tech industry. Techwadi is the leading networking association for Arab American professionals in the Technology industry and is led by the very ambitious Tunisian Ghazi Benothman. Ghazi is the General and Founding partner of Minah Ventures. Minah Ventures is a San Francisco-based venture capital firm, with offices in Boston and Dubai. The firm is focused on making early stage (Seed and Series A) investments in technology startups, looking to leverage the engineering talent present in the Middle East / North Africa region.
I attended a few presentations and think Salem Krimo projected very important points. He talked about how his Software is fully built by an Algerian team. He bragged about how smart his team is and how little he pays them comparing to American standard. Salem talked about how, regardless of where the Software had actually been developed, it can always be categorized as made in USA. He recalled a story of a trip to Algeria where he met a few engineers, builders of a great Software that regulates the usage of water, who were trying to sell it to local government agencies. As he described, because of the complex of inferiority tied to the culture in that part of the world, no one gave them the chance to even present their Software. He took that software, brought it to the US, made few minor changes, added the “Made in USA” label and took it back to Algeria where every door he targeted was wide open for him to present “his” Software.
I had the pleasure of hearing my boss Dr. Fayyad, chief data officer at Yahoo!, talking about the Internet industry and I was very pleased with his humbleness when he told me smiling “I hope I didn’t make us look bad” when he knew that I also work for Yahoo!
I was among the few Tunisians who showed up in the event to represent our community. Besides Ghazi and few others, I got to meet Yacin Bahi, a young talented Tunisian businessman. Yacine, is the founder and president of Ybsis Inc and mentioned a new project he is working on that involves Tunisian developers working form Tunisia.
One thing that really struck me though was how aggressive the representative of the Ministry of Communication and Information Technology was pushing her personal agenda and trying to sell R&D services from people she “personally knows”…
At last, I believe everybody had a common goal which is to make the Arab world the next India or Eastern Europe. But can we really get there when internet providers in that part of the world deliver internet with particular care?