Monday, September 26, 2011

DeepLinking using Browser Manger

  • On the WWW , deeplinking is making a hyperlink that points to a specific page or image on a website,instead of that website's main or home page , such links are called deeplinks.
[hyperlink:]- in a computing ,a hyperlink is a reference to a document that the reader can directly follow, or that is followed automatically.
  • Websites which are built on web technolgies such as Adobe Flash and Ajax often do not support deep linking,this result in usability problems for people visiting such websites. ie..mean : visitors to these websites may be unable to save bookmarks to individualpages r states of the sites,web browser forward and back buttons may not work as expected, and use of the browsers refresh button may return the user to the initial page.
  • However , this is not a fundamental limitations of these technologies, Well-know techniques, and libraries such as SWFAddress , History Keeper, and BrowserManager class, now exist that website creators using Flash or Ajax can use to provide deep linking to pages within their sites .
Now Am providing the example using BrowserManager Class : Deeplinking relies on communication between the browser and application ,the communication is bi-directional ; if a change occur in browser then the application should be notified and if change occur in application then the browser should be notified .this communication is handled by BrowserManager class.

[BrowserManager:]- class use method's in HTML Wrapper's javascript to handle events,
update the browser addressbar, and call other methods.
BrowserManager is a singleton manager that acts as proxy between
the browser and the application

It provide access to the URL in the browser address bar simillar
to accessing the document.location property in JavaScript.

Events are dispatched when url property is changed Listeners
can then responed,alter the URL, and /or block others from
getting the event.

To use BrowserManager, you call the getInstance() method to
get the current instance of the manger, and call methods and
listen to events on that manger

it's Package : mx.mangers
Class : public class BrowserManger
Inheritance : Object

[ singleton pattern ? :]- It's a design pattern that is used to restrict
instaniation of a class to one object , if u create
class as singleton then no way to create more than
one instance, But u can get that single instance
in any number of classes, so all the classes will
share same properties and behaviour of that singleton
object.

Another class URLUtil, is provided to make it easier to parse the url as you need it in your application and write it back to the browser

it's package : mx.utils
Class : public Class URLUtil
Inheritance : Object
[URLUtil:]- The URLUtil class is a static class with methods for working
with full and relative URLs with in Flex

To use deeplinking , you write ActionScript that sets and gets portion of url to determine
which state the application is in.These portions are called fragments,and occur after the
pound sign'#'in the url.

in the following example view=1 is the fragment
eg : http://my.domain.com#view=1

If the user navigate to a new view in your application , you update URL and set view =2
in the url fragment. If user then click the back button ,the BrowserManger is notified of the event, and gives you a chance to change the application state in respond to URL fragment changing back to view=1.

You typically use the methods of the URLUtil class to parse the URL,
This URLUtil class provides methods for detecting server names, port numbers,
and protocol of a URL,In additonal you can use the objectToString() method to convert
an Action script object to a string that you then append to the end of a URL.

Alternatively , we can convert any number of name/value pairs on query string into object
by using URLUtil class's stringToObject(). this lets you then manipulate the fragment
more easily in your application logic.

[Fragment identifier :]- is a short string of characters that refer to
a resource that is subordinate to another primary
resource ,The primary resource is identified by a
URI(uniform resource identifier) and subordinate
resource is identified with fragment identifier.


Fragment identifier is defined by RFC 3986 as an optional
componet of URI refrence, and it must conform to a certain syntax.
Fragment identifier is saparated from rest of URI refrence by '#'.

This sapartor is not considerd part of fragment identifier.


NOTE:When using URL fragment for deeplinking , you actually want to keep the built in history
managment off , otherwise it will interfer with processing.


Follow this four steps in Flash Builder 4 to achieve Deeplinking using BrowserManger Class :

STEP1: start by declaring three variables

1) a refrence to the flex Browsermanger class -- > public var browMang:IBrowserManger;

2)a flag to signal that URL parsing is in progress--> private var isParsing:Boolean;
3) a variable to hold the title for the browser's title bar --> private var title:String;

STEP2: Now , you need to declare your states of your application if you haven't already,
and place a listner for the enterState event. When the state changes , a call
to upate URL will be made.


STEP3: When the application loads , with the help of creationComplete event
you will need to intialize the BrowserManger, and register two listeners,
one for when browser's URL changes and other for application's state changes,
Lastly u will use the callLater() method of UIComponent to parse the URL.

private function application_creationCompleteHandler():void
{
browMang = BrowserManger.getInstance();
browMang.init("","Home");
browMang.addEventListener(BrowserChangeEvent.BROWSER_URL_CHANGE,parseURL);
callLater(parseURL);

STEP4: now , write the code for parseURL() function , this function will be called whenever
the BROWSER_URL_CHANGE event fires.The function parse the URL, and if fragments are found, it will change the title and state of the application accordingly




private function parseURL(event,Event=null):void
{
isParsing = true;

var obj:Object = URLUtil.stringToObject(browMang.fragment);

if (obj.view==undefined)

obj.view="Home";

currentState = obj.view;
title = currentState;
browMang.setTitle(title);

isParsing=false;

}

STEP5: now, u need to do is to update The URL from application though, we will accomplish this
with the function updateURL .

private function updateURL():void
{
title = currentState;
var fragments:String = "";
var obj:Object = {};
if(currentState != "Home")
obj.view = currentState;
fragments = URLUtil.objectToString(obj);
browMang.setTitle(title);
browMang.setFragment(fragments);
}




Friday, September 23, 2011

Methods Invoked in Life Cycle of Components

addChild : is called on parent container .
*sets the parent property of the component.
*Computes style Settings.

Preinitialize: The application has been instantiated but has not yet created any child components.

CreateChildren:Flex calls the createChildren() method in response to the call to the addChild() method to add the component to its parent.

invalidateProperties(): marks a component so that its commitProperties() method gets called during a later screen update.

invalidateSize (): Marks a component so that its measure() method gets called during a later screen update.

invalidateDisplayList (): Marks a component so that its updateDisplayList() method gets called during a later screen update.

Initialize: The application has created child components but has not yet laid out those components.

CommitProperties:Flex calls the commitProperties() method when you use the addChild() method to add a component to a container, or when you call the invalidateProperties() method of the component. Calls to the commitProperties() method occur before calls to the measure() method. This lets you set property values that might be used by the measure() method.
Calls the component’s measure() method.

Measure : calculates the default size, and optionally the default minimum size, of the component. This is an advanced method that you might override when creating a subclass of UIComponent.
The default implementation of measure() sets measuredWidth, measuredHeight, measuredMinWidth, and measuredMinHeight to 0.

LayoutChrome:Calls the component’s (Adobe help mention this method is in UIComponent where as it is in container class) container’s layoutChrome() method.
The Container class, and some subclasses of the Container class, use the layoutChrome() method to define the border area around the container.
Calls the component’s updateDisplayList() method.

UpdateDisplayList(): method sizes and positions the children of your component based on all previous property and style settings, and draws any skins or graphic elements that the component uses. The parent container for the component determines the size of the component itself.

UpdateComplete ispatched when an object has had its commitProperties(), measure(), and updateDisplayList() methods called (if needed). This is the last opportunity to alter the component before it is displayed. All properties have been committed and the component has been measured and layed out.

creationComplete: The application has been completely instantiated and has laid out all components.
To Uninstall Flash players : http://kb2.adobe.com/cps/141/tn_14157.html


We observed kind of Shock Wave plugin crash message with this new release of chrome
for solution check this link :


I unable to open your debugger perspective , chek this below link , this may help-Quick solution -

Version checker for flash player :





Thursday, September 22, 2011

Icon button Extending Button Class

package com.myorg.customComponents
{
import spark.components.Button;
import spark.primitives.BitmapImage;

public class IconButton extends Button
{
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
public function IconButton()
{
super();
}
//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------
//----------------------------------
// icon
//----------------------------------
/**
* @private
* Internal storage for the icon property.
*/
private var _icon:Class;
[Bindable]
/**
*
*/
public function get icon():Class
{
return _icon;
}
/**
* @private
*/
public function set icon(val:Class):void
{
_icon = val;
if (iconElement != null)
iconElement.source = _icon;
}
//--------------------------------------------------------------------------
//
// Skin Parts
//
//--------------------------------------------------------------------------

[SkinPart(required="false")]
public var iconElement:BitmapImage;
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
/**
* @private
*/
override protected function partAdded(partName:String, instance:Object):void
{
super.partAdded(partName, instance);
if (icon !== null && instance == iconElement)
iconElement.source = icon;
}
}
}