Enables Flash websites to move IE forward and backward

Source: Internet
Author: User
Tags gety hash

Preface:
After writing the traffic statistics tutorial, I thought it would be easy to complete this article. Later I found out that I had encountered difficulties. Because iframe is used to control the main HTML variables, in the first place, considering that _ parent is used to open the parent window, and the parent level in Flash is _ parent, therefore, it is taken for granted that iframe accesses the primary html through _ parent. As a result, after a long time, it still prompts that _ parent is not defined.
For this reason, I went to Baidu to see how to access the main html through iframe. Dizzy, it turns out there is no underline, so I changed it and found a new problem, that is, the error "no permission" is prompted. This problem was encountered in the previous decompilation games, caused by cross-origin access. It's strange that my files are all local. Why not? After suffering for half an hour, I decided to use IIS for testing. Well, IIS is successful. Does the file protocol have no permissions? Still cannot recognize domain names? I have not studied this.

--------

Effect preview (at the requirement of wolf2999, this time I will not put the Supergirl stuff up, and it is still a bit difficult to add this function on my website because the structure is a bit complicated ):

Http://hbro.cincn.com/hbro/cours... ex_flash.html # page1

Click the button in the row on the left and you will find that the address bar is changed during the animation effect jump, but it is obvious that Flash is not refreshed, and the back button is available. After a few more times, try to press the back button, and Flash will not refresh, but it will jump to the page you clicked previously through animation.
In this way, the Flash program is controlled through the IE button. However, in essence, an iframe is being refreshed. Therefore, if the network speed is slow and clicked quickly, some pages will be skipped.

Implementation principle:
I found a lot of information. I wanted to add the address of the asfunction protocol to the IE history record, but it seems impossible. In Digi's pull, I understand that you can achieve control by refreshing iframe. The process is as follows:
1. Click a so-called link in Flash to execute an action. Some parameters in this status use getURL to a fixed page in iframe. For example, I have clicked page1, so the address of geturlwill be statistics.html? Page1
2 bytes? Page1,statistics.html? Page2,statistics.html? Page3,statistics.html? Page4 page. What is the final position in statistics.html? Page4
3. Click the back button of the browser, and iframewill return statistics.html? Page3. However, this alone won't control Flash. Therefore, when statistics.html is enabled, enable a function that controls Flash to implement the IE fallback function. The same is true for moving forward.

 

Specific practices:
1.1 create a new Flash file and save it as index_flash.fla
1.2 Create a MC in this document named pagesButtons_clip. Put a button in it and write the code:
On (release ){
_ Parent. loadNews (_ name); // This function is used to redirect pages in Flash.
   }
1.3 load another dynamic text with the variable name _ name
1.4 put four pagesButton_clip in the main scenario and name them page1, page2, page3, and page4 respectively.
1.5 create a new MC in the home scene, the instance name is pages, and put the MC with the instance name page1, page2, page3, and page4 in it.
1.6 create a mask for pages at an appropriate position.
1.7 The following code can be written. In this jump, I will locate the corresponding page to the mask so that the page will be displayed, while others will be hidden.
Frame write in the main scenario:
Var initx = mask. _ x; // first, locate an initial vertex, which is a constant located on the page.
Var inity = mask. _ y; // same as above
Var targetx = initx;
Var targety = inity; // these two variables are also used for locating. Using Korean buffer formula algorithms, MC can be moved slowly to (targetx, targety.
This. onEnterFrame = function (){
Pages. _ x = pages. _ x-0.2 * (pages._x-pages.tar getx );
Pages. _ y = pages. _ y-0.2 * (pages._y-pages.tar gety );
}; // This is the buffer formula
Function loadNews (href) {// define the function triggered by the button
Pages.tar getx = initx-pages [href]. _ x;
Pages.tar gety = inity-pages [href]. _ y; // first let target locate to the current MC (that is, the input parameter href), then the buffer formula will display the input MC, and others will be hidden.
Fscommand ("setAddress", href); // you can specify the content in the address bar to refresh the page. This command is returned in JS.
GetURL ("statistics.html? "+ Href," stat "); // enable iframe to record the instance name href from the current point to the MC
}

2.1 publish an HTML file and a SWF file in Flash with fscommand tracking, and then remove the HTML check on the format tab of the publishing settings.
2.2 Open the index_flash.html file with the notebook and find the // place your code here sentence. Write
If (command = "setAddress "){
Document. location. hash = args
        }
2.3 then define the onLoad execution function JS_LoadNews
Function JS_LoadNews (){
Window. open ("statistics.html? "+ Document. location. hash. slice (1)," stat ") // open an iframe with parameters named stat.
}
2.4 add an iframe according to the JS in the previous step
<Iframe noscroll border = "0" src = "about: blank" width = "1" height = "1" name = "stat" id = "stat"> </iframe>
2.5 add onload = JS_LoadNews () to the body tag ()

3.1 Create an HTML file named statistics.html. Write the code for controlling Flash here:
<Script language = "javascript">
Function pageLoad (){
Window. parent. index_flash.setVariable ("link", too many doc ument. location. search. slice (1) // parent refers to the parent framework, which can point to the FLASH file, location. search is an address parameter that contains "? ", So use slice (1) to remove it.
  }
</Script>
<Body onload = pageLoad ()>
</Body>
3.2 The above code sets the link value in Flash. In order to trigger the Flash function, addProperty is used in Flash to trigger the related function:
Append frame code:
This. addProperty ("link", getLink, setLink );
Function getLink (){
}
Function setLink (link ){
Fscommand ("setAddress", link );
Pages.tar getx = initx-pages [link]. _ x;
Pages.tar gety = inity-pages [link]. _ y;
}

So far, all three steps to implement the backward forward function have been completed.

The above four articles are part of the first series of Flash full-site applications-bringing Flash closer to HTML, with the aim of "solving the congenital defects of Flash websites with the advantages of HTML ". Today, with the increasingly powerful Flash functions and increasingly distinctive features, the path to HTML for Flash may be "the opposite". In addition, these program codes are boring, therefore, it cannot resonate with everyone. I was going to write this content later. I just mentioned it to solve the problem of the volcano brother.

In the next series, I will write some multimedia applications that are more popular. This includes switching pictures on my website, combining WMP music, video player, and synchronous display of lyrics (but I have already written this content, so I will not repeat it now ).
Preview pictures and music players:
Http://hbro.cincn.com/cindex.htm
PS: remind the volcano brother that I didn't use the positioning technology in the news here. If the refresh fails, I don't need to point it out to me.

 

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.