Wednesday, September 10, 2008

Event Handling In Flash




An event handler method is a method of a class that is invoked when


an event occurs on an instance of that class. For example, the


MovieClip class defines an onPress event handler that is invoked


whenever the mouse is pressed on a movie clip object. Unlike other


methods of a class, however, you don't invoke an event handler directly;


Flash Player invokes it automatically when the appropriate event occurs.
The following ActionScript classes are examples of classes that define event handlers: Button, ContextMenu, ContextMenuItem, Key, LoadVars, LocalConnection, Mouse, MovieClip, MovieClipLoader, Selection, SharedObject, Sound, Stage, TextField, XML and XMLSocket. For more information about the event handlers they provide, see the entries for each class in ActionScript 2.0 Language Reference. The word handler is added in the title of each event handler.
By default, event handler methods are undefined: when a particular event occurs, its corresponding event handler is invoked, but your application doesn't respond further to the event. To have your application respond to the event, you define a function with the function statement and then assign that function to the appropriate event handler. The function you assign to the event handler is then automatically invoked whenever the event occurs.
An event handler consists of three parts: the object to which the event applies, the name of the object's event handler method, and the function you assign to the event handler. The following example shows the basic structure of an event handler:


object.eventMethod = function () { // Your code here, responding to event.

}


For example, suppose you have a button named next_btn on the Stage. The following code assigns a function to the button's onPress event handler; this function advances the playhead to the next frame in the current timeline:

next_btn.onPress = function () { nextFrame();

}

Assigning a function reference:
In the previous code, the nextFrame() function is assigned to an event handler for onPress. You can also assign a function reference (name) to an event handler method and later define the function, as shown in the following example:

// Assign a function reference to button's onPress event handler.next_btn.onPress = goNextFrame;

// Define goNextFrame() function.function goNextFrame() { nextFrame();

}

Notice in the following example that you assign the function reference, not the function's return value, to the onPress event handler:

// Incorrect!
next_btn.onPress = goNextFrame();
// Correct.
next_btn.onPress = goNextFrame;

Receiving passed parameters:
Some event handlers receive passed parameters that provide information about the event that occurred. For example, the TextField.onSetFocus event handler is invoked when a text field instance gains keyboard focus. This event handler receives a reference to the text field object that previously had keyboard focus.
For example, the following code inserts some text into a text field that no longer has keyboard focus:

this.createTextField("my_txt", 99, 10, 10, 200, 20);
my_txt.border = true;
my_txt.type = "input";
this.createTextField("myOther_txt", 100, 10, 50, 200, 20);
myOther_txt.border = true;
myOther_txt.type = "input";
myOther_txt.onSetFocus = function(my_txt:TextField) {
my_txt.text = "I just lost keyboard focus";
};


Event handlers for runtime objects:
You can also assign functions to event handlers for objects you create at runtime. For example, the following code creates a new movie clip instance (newclip_mc) and then assigns a function to the clip's onPress event handler:

this.attachMovie("symbolID", "newclip_mc", 10);
newclip_mc.onPress = function (
)
{ trace("You pressed me");

Overriding event handler methods:
By creating a class that extends an ActionScript class, you can override event handler methods with the functions that you write. You can define an event handler in a new subclass that you can then reuse for various objects by linking any symbol in the library of the extended class to the new subclass. The following code overrides the MovieClip class's onPress event handler with a function that decreases the transparency of the movie clip:

// FadeAlpha class -- sets transparency when you click the movie clip.
class FadeAlpha extends MovieClip {
function onPress() {
this._alpha -= 10;
}

}




Using button and movie clip event handlers:
You can attach event handlers directly to a button or movie clip instance on the Stage by using the onClipEvent() and on() event handlers. The onClipEvent() event handler broadcasts movie clip events, and the on() event handler handles button events.
To attach an event handler to a button or movie clip instance, click the button or movie clip instance on the Stage to bring it in focus, and then enter code in the Actions panel. The title of the Actions panel reflects that code will be attached to the button or movie clip: Actions Panel - Button or Actions Panel - Movie Clip. For guidelines about using code that's attached to button or movie clip instances,
Do not confuse button and movie clip event handlers with component events, such as SimpleButton.click, UIObject.hide, and UIObject.reveal, which must be attached to component instances and are discussed in Using Components.

You can attach onClipEvent() and on() only to movie clip instances that have been placed on the Stage during authoring. You cannot attach onClipEvent() or on() to movie clip instances that are created at runtime (using the attachMovie() method, for example). To attach event handlers to objects created at runtime, use event handler methods or event listeners.
Attaching onClipEvent() and on() handlers is not a recommended practice. Instead, you should put your code in frame scripts or in a class file, as demonstrated throughout this manual. For more information,

Monday, September 8, 2008

Google Chrome Features


Google Chrome:
is a web browser built with open source code developed by Google. The name is derived from the graphical user interface frame, or "chrome", of web browsers.Chromium is the name of the open source projectbehind Google Chrome,released under the BSD license.

The release announcement was originally scheduled for 3 September 2008, and a comic by Scott McCloud was to besent to journalists and bloggers explaining the features of and motivations for the new browser. Copies intended for Europe were shipped early and German blogger Philipp Lenssen of Google Blogoscopedmade a scannedcopy of the 38-page comic available on his website after receiving it on 1 September 2008.Google subsequentlymade the comic available on Google Books and their site and mentioned it on its official blog along with an explanation for the early release.

Beta release:
A beta version for Microsoft Windows was released on 2 September 2008 in 43 languages. Google said more would be coming soon.On 3 September, a Slashdot news item drew attention to a passage in the terms of service for the initial beta release, which seemed to grant to Google a license to all content transferred via the Chrome browser.Thepassage in question was inherited from the general Google terms of service.The Register summarized the passageas "Your copyright goes up in smoke." On the same day, Google responded to this criticism by stating that the language used was borrowed from other products, and removed the passage in question from the Terms of Service.Googlenoted that this change would "apply retroactively to all users who have downloaded Google Chrome.
The first release of Google Chrome passed the Acid1 and Acid2 tests, but does not pass the Acid3 test; however, itscores 78/100, which is higher than both Internet Explorer 7 and Firefox 3.

Design:
Primary design goals were improvements in security, speed, and stability compared to existing browsers. There also were extensive changes in the user interface.Chrome was assembled from 26 different code libraries from Google and others from third parties such as Netscape.
SecurityChrome periodically downloads updates of two blacklists (one for phishing and one for malware), and warns users when they attempt to visit a harmful site. This service also is made available for use by others via a free public API called "Google Safe Browsing API". In the process of maintaining these blacklists, Google also notifies the ownersof listed sites who may not be aware of the presence of the harmful software.

Speed:
The JavaScript virtual machine was considered a sufficiently important project to be split off (as was Adobe/Mozilla'sTamarin) and handled by a separate team in Denmark. Existing implementations were designed "for small programs, wherethe performance and interactivity of the system weren't that important", but web applications such as Gmail "areusing the web browser to the fullest when it comes to DOM manipulations and Javascript". The resulting V8 JavaScriptengine has features such as hidden class transitions, dynamic code generation, and precise garbage collection. Tests by Google show that V8 is about twice as fast as Firefox 3 and the Safari 4 beta.
Application support:
A feature of the Google browser (in fact one of the main reasons it was created) is the Application Mode. This is muchmore than just hiding the omnibox (navigation bar). This allows web pages to break free of the restrictions of the current browser paradigm. The browser paradigm freely allows the user to reload a page, navigate away or close the window, which would be disastrous for an application that is editing sensitive content. Although this appears to bea minor change, the lack of this feature means that there is no mechanism to prevent the sudden loss of unsaved data(without a major investment in an far more complex AJAX architecture). Other features still are required, such as desktop interaction, filetype support, and database access. This limits the browser chrome so as not to "interruptanything the user is trying to do", allowing web applications to run alongside local software (similar to Mozilla Prism and Fluid).

User interface:
The main user interface includes back, forward, refresh, bookmark, go, and cancel options. The options are similar toSafari, while the location of the settings is similar to Internet Explorer 7/8. The minimize, maximize, and closewindow buttons are based on Windows Vista.
When the window is not maximized, the tab bar appears directly under the standard Windows title bar. When maximized,the title bar disappears, and instead, the tab bar is shown at the very top of the screen. Unlike other browsers such as Internet Explorer or Firefox which also have a full-screen mode that hides the operating system's interface completely, Chrome can only be maximized like a standard Windows application. Therefore, the Windows task bar, systemtray, and start menu link still take space at all times unless they have been configured to hide at all times.
As opposed to the latest versions of Firefox and Internet Explorer, which allow the user to adjust the display dimensions of a web page completely, Chrome allows the resizing of the text only. Therefore, a web page 800 pixels wide, for example, will still be 800 pixel wide—even if the user resizes it. Only the text will be affected by theresizing.
Chrome includes Gears, which adds developer features that may, or may not, become web standards, typically relatingto the building of web applications (including offline support).
Chrome replaces the browser home page which is displayed when a new tab is created with a New Tab Page. This shows thumbnails of the nine most visited web sites along with the sites most often searched, recent bookmarks, and recently closed tabs.[11] This concept appeared first with Opera's Speed Dial.

Privacy:
Users quickly began raising privacy concerns about data collection in Chrome. The omnibar's auto-suggest features send data back to Google about the keystrokes inputted. A Google representative said that about 2% of the data wouldbe stored along with the IP address of the computer that sent the data. Google also stated users can opt-out byturning off the auto-suggest feature or switching to Incognito.

Security flaws:
Multiple security experts have criticized what serves as the automatic file download feature that comes enabled by default in Google Chrome. They argued that it could be used easily by an attacker to trick a user into opening a malicious executable file.A denial-of-service vulnerability also has been found that allows a malicious web page to crash the whole web browser.Google Chrome developers confirmed the flaw, and it already has been fixed in the SVN repository.