Flex deep link (deep link) browsermanager.

Source: Internet
Author: User
Tags addchild

Recently, when I was playing a game, I found that the "#" character is automatically added to the URL when I log out. It is strange that Google + Baidu did not find the answer for countless times. Today, I accidentally saw several groups of friends asking me to get the URL through "browsermanager". So I checked the API carefully and found "historymanager". I finally understood the problem.

The web page we usually see can be viewed through the browser's "Forward" and "backward". Similarly, the embedded page flash can also achieve this function. The method is implemented through two methods: historymanageer class and browsermanager class. Historymanageer class is mainly used in flex2 and is rarely used after flex3. I will introduce these two methods later.

Back to the question that "#" is automatically added to the URL: The reason is that the default historymanagementenabled attribute of application is true, that is, the historymanageer class function is automatically enabled, any changes caused by addchild or removechild components controlled by the program in the application will be recorded in the Flash history, resulting in URL rewriting and adding the "#" character. So there is this strange. In flex3, The historymanager feature is enabled by default in the flex project, including the accordion and tabnavigator components. For components that do not enable this function by default, if you want to implement this function, you need to register it separately. The following two articles are used to describe:
A website consists of several webpages. Links between webpages are called hyperlinks. The link serves as a bridge between a webpage and a webpage. So, is there a way for a flash whole site to implement the link between flash pages (more appropriately, each function module. For example, if I want to enter a link in the browser, I can link to a page in the Flash website-a function module, instead of entering through the function navigation of the first page of the Flash site each time. How can we implement the page-based functions of flash. Can it be implemented?
The answer is yes. The above functions can be implemented through FLEX deep link.

Flex deep link (deep link)-1. Introduction to deep link.

In fact, deep link depends on the interaction between flash and the browser. By getting the parameters # following the link address, we can mark the page. When you are in the flex hosts file, it can be seen that deep link is also implemented through interaction with browsers. if the browser does not support JavaScript or disables JavaScript, deep link cannot be used.
For deep link applications, the most important thing is to learn to apply the browsermanager and historymanager classes. From Simplicity to difficulty, let's first talk about the application of historymanager.

Flex deep link (deep link)-second, historymanager.


The historymanager function is enabled by default in the flex project. For example, when you use the accordion and tabnavigator components to switch between different regions, flex automatically records various States, we can move forward and backward by clicking the "Forward" and "back" buttons in the browser. When you switch the areas of these components, flex will automatically add parameters after the webpage link, to record the status of the current page.
By default, historymanager is enabled. You can disable this function by setting the historymanagementenabled attribute of each component or application to false (true by default.
There is nothing to talk about. The key is how to use the historymanager function in some common components. The default navigator container build supports this function. To enable some common components to support this function, you must:
1. Implement the MX. Managers. ihistorymanagerclient interface.
2. Register with historymanager's register () method.
3. When the component status changes, save the component status.
4. Save and read the component status by implementing the savestate () and loadstate () Methods of ihistorymanagerclient.

 
Take checkbox as an example:

 
<? XML version = "1.0"?>
<Mx: checkbox
Xmlns: MX = "http://www.adobe.com/2006/mxml"
Label = "check me"

Implements = "MX. Managers. ihistorymanagerclient" // Key Step 1: implement the interface
Creationcomplete = "MX. Managers. historymanager. Register (this);" // Key Step 2. register the component
Change = "boxchanged (event)" // Key Step 3. Save the status when the Component Changes
>

<Mx: SCRIPT> <! [CDATA [
Import MX. Managers. historymanager;
// Implements the savestate () method save status of ihistorymanagerclient
Public Function savestate (): object {
Return {selected: Selected };
}
// Implements the ihistorymanagerclient loadstate () method reading status
Public Function loadstate (State: Object): void {
VaR newstate: Boolean = State;

If (newstate! = Selected ){
Selected = newstate;
} Else {
If (newstate ){
;
} Else {
Selected = true;
}
}
}

// Save status
Private function boxchanged (E: Event): void {
Historymanager. Save ();
}
]> </MX: SCRIPT>

</MX: checkbox>
Note: If you place components that implement the historymanager function into the module and call them in the main program, the historymanager function is useless.
The sparrow is small and dirty. The above example is a typical case of how to implement historymanager for any component. Click "Forward" and "back" in the browser to restore the previous or next state.
The browsermanager class is more complex than the historymanager class. The browsermanager class is like a proxy between the flex program and the browser. When the address in the browser address bar changes, the browser informs the flex program through the browsermanager class.
You can use the getinstance () method of the browsermanager class to obtain an instance that implements the ibrowsermanager interface. In this way, you can access its settitle () and setfragment () methods and attributes. Next I will introduce some properties and methods of the browsermanager class.

Flex deep link (deep link)-method:

1. INIT (fragment, title)
This method defines the default link parameters and webpage titles. It is generally used during initialization. For example:
Browsermanager. INIT ("", "test deep linking"); defines a webpage with the parameter "test deep linking" as null.
2. settitle (title)
This method is used to set the webpage title. For example:
Browsermanager. settitle ("the new title") sets the webpage title to "the new title ".
3. setfragment (fragment)
This method is used to set webpage parameters. For example:
Browsermanager. setfragment ("ID = 3") sets the parameter "id = 3 ".

Flex deep link-attributes:

1. url
Browsermanager. URL to obtain the complete page Link.
2. Base
Browsermanager. Base obtains the base address of the page.
3. Fragment
Browsermanager. fragment get the parameters after page Link.
4. lasturl
Browsermanager. lasturl to get the link of the previous page -- IE6 I failed to get, Firefox is correct. You can try it on your own.

Note: The browsermanager is an instance of the browsermanager class. The instantiation process is as follows:
Import MX. Events. browserchangeevent;
Import MX. Managers. ibrowsermanager;
Import MX. Managers. browsermanager;
Private var browsermanager: ibrowsermanager;
Private function initapp (): void {
Browsermanager = browsermanager. getinstance ();
Browsermanager. addeventlistener (browserchangeevent. browser_url_change, parseurl );
Browsermanager. INIT ("", "test deep linking ");
}

Flex deep link-how to analyze URLs

You can use the urlutil class to analyze URLs conveniently.
The class path MX. utils. urlutil, for example, http: // 127.0.0.1/index.html # A = 3 & B = 1
VaR O: Object = urlutil. stringtoobject (browsermanager. fragment ,"&");
Trace (O. A, o. B)
In turn, set the address bar link:
O. A = 5; O. B = 7;
VaR S: String = urlutil. objecttostring (O ,"&");
Browsermanager. setfragment (s );
Note: If the second parameter of urlutil. objecttostring () is null, the default parameter Delimiter is.
 
Browsermanager events
The browsermanager class has three types of events:
1. applicationurlchange event;
This event is sent when the setfragment () method is called to change the URL when the program is executed.
2. browserurlchange event;
This event is sent when you manually change the browser link or click "Forward" or "back.
3. urlchange event;
This event is triggered when the applicationurlchange event or browserurlchange event is distributed.

Flex deep link-Get link information

You can obtain the link information through the browsermanager class attributes and urlutil methods, for example:
VaR URL: String = browsermanager. url;
Baseurl = browsermanager. base;
Fragment = browsermanager. Fragment;
Previusurl = E. lasturl;

Fullurl = mx. utils. urlutil. getfullurl (URL, URL );
Port = mx. utils. urlutil. getport (URL );
Protocol = mx. utils. urlutil. getprotocol (URL );
Servername = mx. utils. urlutil. getservername (URL );
Issecure = mx. utils. urlutil. ishttpsurl (/URL );

The specific meaning is also clear, so I will not talk much about it.
The browsermanager class is roughly the content above. Note that the browsermanager class and historymanager class cannot be used at the same time, that is, the browsermanager class cannot be used again. When you use the browsermanager class, the historymanager class is automatically disabled.
Since the parameters can be obtained, the functions at the beginning of the article will be useless. Get the corresponding parameters in the initialization program, and then display them according to these parameters. Similar to. net, ASP, and PHP, everything is regular. With the help of the browsermanager class and some program control, I can enter http: // 127.0.0.1/news.html # id = 20 in the browser to display a news page on the Flash site.

Recently, when I was playing a game, I found that the "#" character is automatically added to the URL when I log out. It is strange that Google + Baidu did not find the answer for countless times. Today, I accidentally saw several groups of friends asking me to get the URL through "browsermanager". So I checked the API carefully and found "historymanager". I finally understood the problem.

The web page we usually see can be viewed through the browser's "Forward" and "backward". Similarly, the embedded page flash can also achieve this function. The method is implemented through two methods: historymanageer class and browsermanager class. Historymanageer class is mainly used in flex2 and is rarely used after flex3. I will introduce these two methods later.

Back to the question that "#" is automatically added to the URL: The reason is that the default historymanagementenabled attribute of application is true, that is, the historymanageer class function is automatically enabled, any changes caused by addchild or removechild components controlled by the program in the application will be recorded in the Flash history, resulting in URL rewriting and adding the "#" character. So there is this strange. In flex3, The historymanager feature is enabled by default in the flex project, including the accordion and tabnavigator components. For components that do not enable this function by default, if you want to implement this function, you need to register it separately. The following two articles are used to describe:
A website consists of several webpages. Links between webpages are called hyperlinks. The link serves as a bridge between a webpage and a webpage. So, is there a way for a flash whole site to implement the link between flash pages (more appropriately, each function module. For example, if I want to enter a link in the browser, I can link to a page in the Flash website-a function module, instead of entering through the function navigation of the first page of the Flash site each time. How can we implement the page-based functions of flash. Can it be implemented?
The answer is yes. The above functions can be implemented through FLEX deep link.

Flex deep link (deep link)-1. Introduction to deep link.

In fact, deep link depends on the interaction between flash and the browser. By getting the parameters # following the link address, we can mark the page. When you are in the flex hosts file, it can be seen that deep link is also implemented through interaction with browsers. if the browser does not support JavaScript or disables JavaScript, deep link cannot be used.
For deep link applications, the most important thing is to learn to apply the browsermanager and historymanager classes. From Simplicity to difficulty, let's first talk about the application of historymanager.

Flex deep link (deep link)-second, historymanager.


The historymanager function is enabled by default in the flex project. For example, when you use the accordion and tabnavigator components to switch between different regions, flex automatically records various States, we can move forward and backward by clicking the "Forward" and "back" buttons in the browser. When you switch the areas of these components, flex will automatically add parameters after the webpage link, to record the status of the current page.
By default, historymanager is enabled. You can disable this function by setting the historymanagementenabled attribute of each component or application to false (true by default.
There is nothing to talk about. The key is how to use the historymanager function in some common components. The default navigator container build supports this function. To enable some common components to support this function, you must:
1. Implement the MX. Managers. ihistorymanagerclient interface.
2. Register with historymanager's register () method.
3. When the component status changes, save the component status.
4. Save and read the component status by implementing the savestate () and loadstate () Methods of ihistorymanagerclient.

 
Take checkbox as an example:

 
<? XML version = "1.0"?>
<Mx: checkbox
Xmlns: MX = "http://www.adobe.com/2006/mxml"
Label = "check me"

Implements = "MX. Managers. ihistorymanagerclient" // Key Step 1: implement the interface
Creationcomplete = "MX. Managers. historymanager. Register (this);" // Key Step 2. register the component
Change = "boxchanged (event)" // Key Step 3. Save the status when the Component Changes
>

<Mx: SCRIPT> <! [CDATA [
Import MX. Managers. historymanager;
// Implements the savestate () method save status of ihistorymanagerclient
Public Function savestate (): object {
Return {selected: Selected };
}
// Implements the ihistorymanagerclient loadstate () method reading status
Public Function loadstate (State: Object): void {
VaR newstate: Boolean = State;

If (newstate! = Selected ){
Selected = newstate;
} Else {
If (newstate ){
;
} Else {
Selected = true;
}
}
}

// Save status
Private function boxchanged (E: Event): void {
Historymanager. Save ();
}
]> </MX: SCRIPT>

</MX: checkbox>
Note: If you place components that implement the historymanager function into the module and call them in the main program, the historymanager function is useless.
The sparrow is small and dirty. The above example is a typical case of how to implement historymanager for any component. Click "Forward" and "back" in the browser to restore the previous or next state.
The browsermanager class is more complex than the historymanager class. The browsermanager class is like a proxy between the flex program and the browser. When the address in the browser address bar changes, the browser informs the flex program through the browsermanager class.
You can use the getinstance () method of the browsermanager class to obtain an instance that implements the ibrowsermanager interface. In this way, you can access its settitle () and setfragment () methods and attributes. Next I will introduce some properties and methods of the browsermanager class.

Flex deep link (deep link)-method:

1. INIT (fragment, title)
This method defines the default link parameters and webpage titles. It is generally used during initialization. For example:
Browsermanager. INIT ("", "test deep linking"); defines a webpage with the parameter "test deep linking" as null.
2. settitle (title)
This method is used to set the webpage title. For example:
Browsermanager. settitle ("the new title") sets the webpage title to "the new title ".
3. setfragment (fragment)
This method is used to set webpage parameters. For example:
Browsermanager. setfragment ("ID = 3") sets the parameter "id = 3 ".

Flex deep link-attributes:

1. url
Browsermanager. URL to obtain the complete page Link.
2. Base
Browsermanager. Base obtains the base address of the page.
3. Fragment
Browsermanager. fragment get the parameters after page Link.
4. lasturl
Browsermanager. lasturl to get the link of the previous page -- IE6 I failed to get, Firefox is correct. You can try it on your own.

Note: The browsermanager is an instance of the browsermanager class. The instantiation process is as follows:
Import MX. Events. browserchangeevent;
Import MX. Managers. ibrowsermanager;
Import MX. Managers. browsermanager;
Private var browsermanager: ibrowsermanager;
Private function initapp (): void {
Browsermanager = browsermanager. getinstance ();
Browsermanager. addeventlistener (browserchangeevent. browser_url_change, parseurl );
Browsermanager. INIT ("", "test deep linking ");
}

Flex deep link-how to analyze URLs

You can use the urlutil class to analyze URLs conveniently.
The class path MX. utils. urlutil, for example, http: // 127.0.0.1/index.html # A = 3 & B = 1
VaR O: Object = urlutil. stringtoobject (browsermanager. fragment ,"&");
Trace (O. A, o. B)
In turn, set the address bar link:
O. A = 5; O. B = 7;
VaR S: String = urlutil. objecttostring (O ,"&");
Browsermanager. setfragment (s );
Note: If the second parameter of urlutil. objecttostring () is null, the default parameter Delimiter is.
 
Browsermanager events
The browsermanager class has three types of events:
1. applicationurlchange event;
This event is sent when the setfragment () method is called to change the URL when the program is executed.
2. browserurlchange event;
This event is sent when you manually change the browser link or click "Forward" or "back.
3. urlchange event;
This event is triggered when the applicationurlchange event or browserurlchange event is distributed.

Flex deep link-Get link information

You can obtain the link information through the browsermanager class attributes and urlutil methods, for example:
VaR URL: String = browsermanager. url;
Baseurl = browsermanager. base;
Fragment = browsermanager. Fragment;
Previusurl = E. lasturl;

Fullurl = mx. utils. urlutil. getfullurl (URL, URL );
Port = mx. utils. urlutil. getport (URL );
Protocol = mx. utils. urlutil. getprotocol (URL );
Servername = mx. utils. urlutil. getservername (URL );
Issecure = mx. utils. urlutil. ishttpsurl (/URL );

The specific meaning is also clear, so I will not talk much about it.
The browsermanager class is roughly the content above. Note that the browsermanager class and historymanager class cannot be used at the same time, that is, the browsermanager class cannot be used again. When you use the browsermanager class, the historymanager class is automatically disabled.
Since the parameters can be obtained, the functions at the beginning of the article will be useless. Get the corresponding parameters in the initialization program, and then display them according to these parameters. Similar to. net, ASP, and PHP, everything is regular. With the help of the browsermanager class and some program control, I can enter http: // 127.0.0.1/news.html # id = 20 in the browser to display a news page on the Flash site.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.