Skip to main content
Inspiring
September 1, 2008
Answered

Opening new page to a Specific frame

  • September 1, 2008
  • 1 reply
  • 950 views
I am still learning Action Script but I have a problem with writing the full script for combing navigate to new URL and gotoAndPlay. More specifically what I want to do is use a button which when clicked will open a new page and then start playing my Flash movie at a certain frame on the Timeline. I have used buttons to navigate to a new URL and used the gotoAndPlay ( ) ; command to play a certain frame, both have been successful but when I combine the two I run into trouble. What happens is the new page loads correctly and goes to the specific frame but then opens the browser in a new window with the movie playing from the beginning. The correct sequence within the correct Webpage is playing but only if I close the current page, in other words what I am trying to achieve is running but in the background.

I have attached some of the code I have tried if that helps. Many Thanks.
This topic has been closed for replies.
Correct answer 1485
How extensive are the corresponding text changes on the HTML page? How many HTML pages are there? The reason I am asking is that if HTML content is not big - your best bet may be to load all the HTML content at once and hide/unhide parts of it based on the commands that come from Flash.

But if you are sticking to your guns:

Your use case, as you described it, is:
1. user clicks a button on a column
2. the column clicked moves across the movie
3. the movie starts to play a different section
4. the text on the web page changes to match the new movie sequence.

There is a problem here - No 4 requires browser reloading. I believe user experience will not be all that good because of the visual break (new html page loading) after all the animation sequence after the click occurs. Perhaps a better experience can be:

click --> load appropriate page --> perform animation sequence.

As for the variables that you add to the request, conceptually it is not different from appending url variables to the url string:

You can do it this way:

var url:String = "www.domain.com/mypage.html?myVariable1=something&myVariable2=somethingElse";

Or you can do it this way:
ar url:String = "www.domain.com/mypage.html";
var variables:URLVariables = new URLVariables();
variables.myVariable1 = "something";
variables.myVariable2 = "somethingElse";
var request:URLRequest = new URLRequest(url);
request.data = variables;

I hope you see the similarity. The result is the same - Flash sends request with the variables.
You may perceive the second way as more cumbersome but there are several advantages of doing it this way. One of the most important is that Flash automatically makes variables values url formatted which is critical when you send strings with special characters. In addition, when you send many variables - it is much more manageable than keeping track of the variable and making assignments in one-line url string.

How you deal with it further depends on how good you are with HTML and JavaScript OR server side processing.

Say you need to start your Flash movie from a certain frame (say No 50). You may want to:
1. Load HTML page with a url that contains a frame number: variables.startframe = 50;
2. You need to read this variable with JavaScript and write an appropriate embed tag. There are several ways to do that. Read about FlashVars. It could be (in the embed tag): src="myMovie.swf?startframe=50" where 50 comes from browser location string.
3. Inside Flash you will utilize LoaderInfo.parameters method to extract the value of the variable startframe.
4. Write code that will perform and animation based on this variable/parameter.

I guess a question is "How good are you at HTML and JavaScript?"

Very Grateful for your help and comments. You are quite correct that the sequence needs to be addressed therefore what I have done is button click, load new URL, perform animation and then play the movie sequence. Using "_self" meant that the build up of browser windows was eliminated plus the sequence you suggested means that the momentary pause is only evident at the time the button is clicked.

What all this means is that the user interaction works in line with my objectives. The simplest way of achieving a similar result would have been to load the complete text and then hide and unhide appropriate parts of the page as you suggested but I have a feeling that this method would only hold good for the time being as I expect the pages/content to grow in size.

The main thing is problem solved, thanks to you.

1 reply

Inspiring
September 2, 2008
There is no getURL in AS3 (unless you write this method yourself). In order for Flash to move to a particular frame from the start you need to indicate to the player where it needs to go. This can be accomplished by writing JS function that will embed Flash with particular FlashVar (say, frame number) which, in turn, will be read by flash code and do whatever you need.

What is 1961 in getURL? Second parameter in AS2 getURL is a target window.
1485Author
Inspiring
September 2, 2008
Thanks for the reply. I don't think I am making it very easy for people to help. I am attaching the exact code that produces the results I mentioned. I have been trying too many methods and got thoroughly lost. I am using Action Script 3.0 and both the navigate to URL and gotoAndPlay (when accessing the same movie on the same webpage) commands work fine on their own but I am not sure where I should insert the "target frame" piece of script to navigate to a specific frame on a new webpage. As the code stands the mouse click does navigate to the correct URL but will not correctly play the sequence at the correct frame. What actually seems to happen is the the movie starts to play at the correct frame but stops then begins at the very beginning of the movie.Plus there are 2 browser windows open, the prime being the correct webpage and the secondary the original webpage where the mouse click first took place.

If using "var" is the answer where exactly should I insert this piece of code. Thanks again.
Inspiring
September 2, 2008
I am not sure if you realize that when you open the same swf in a different browser window - it is a totally new instance of the file and it has nothing to do with the instance from which you opened it. So the command gotoAndPlay (1961);refers to the opener and is not read by the opened Flash.

If you want to influence a new instance one of the ways is to create JavaScript code in the newly opened page. This JS will write an embed tag for a new instance. One of the things you can do is to append variables to the url of your application (NOTE: not in the browser url - in the embed code that embeds you swf): mySWF.swf?var1=aha&action=uhu&frame=1961. Within the FLash you can read these variables and wrote a code that will do what is prescribed.

ADDITION:

Can you tell what you are trying to accomplish? Why do you need to open it in a new window? Perhaps there is a better way to implement you vision...