Flex deep link)

Source: Internet
Author: User

Recently, when I was working on the flex project, 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 pages 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 explain that 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 you want to enter a link in your browser, you can link to a page in the Flash website-a function module, instead of entering each time through the function navigation of the first page of the entire Flash site. 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. 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 release a project in flex bulid3, the directory you published automatically generates a folder named history, which contains three files: history.js, historyframe.html, and history.css. 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:

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 can define the default link parameters and web page 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 as "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 (deep link)-attribute: 1.url browsermanager. URL to obtain the complete link of the page. 2. Base browsermanager. Base obtains the base address of the page. 3. Fragment browsermanager. fragment get the parameter after page Link. 4. lasturl browsermanager. lasturl gets the link of the previous page -- IE6 I failed to get it, 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 the URL You can use the urlutil class to conveniently analyze the URL class path MX. utils. urlutil, for example, link: 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 urlutil. if the second parameter of the objecttostring () method is null, the default parameter Delimiter is. Browsermanager events the browsermanager class has three types of events: 1. applicationurlchange events; send this event when the program calls methods such as setfragment () to change the URL during execution. 2. browserurlchange event. This event is sent when you manually change the browser link or click forward or backward. 3. urlchange event. This event is triggered when the applicationurlchange event or browserurlchange event is distributed. Flex deep link (deep link)-to obtain link information, you can use the browsermanager class attributes and urlutil methods to obtain link information, such as 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 about it much. 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 can no longer be used. 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. This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/jinxinxin1314/archive/2009/09/18/4564948.aspx

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.