Solved

Flash reads param from html

Posted on 2008-06-23
3
317 Views
Last Modified: 2013-11-11
Hi Experts

I am new to Flash.  I am creating a flash animation which will be a banner across the top of a standard HTML page.

I want the flash to detect what page is showing, then display different text depending on the page.  For example if the user is on the 'about us' page, flash will detect that and display the words 'about us' in a flash movie.

Ideally Flash would read a param from the HTML head of the page.

How is that done?
0
Comment
Question by:willnjen
  • 2
3 Comments
 

Author Comment

by:willnjen
ID: 21852052
Actually, thinking about it...I need to display a different image depending on the page.

So same as my initial description, Flash would read a param from a header, then display an image relevant to the page.

Cheers

Will
0
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
ID: 21852166
Ok, first of all, I'm going to recommend using swfobject. A fantastic JavaScript that lets you add swf movies in a really easy way. Get it here: http://blog.deconcept.com/swfobject/

This is how you would use it:

<code>

Ok, so if we break down the HTML, we can see a bunch of things.

1. We have an "alternate" content to display if the user viewing your website does not have Flash Player installed, you can add a link there to Adobe's website or whatever.
2. The var so = new SWFObject ... has a bunch of arguments, in order of appearance, we have the following:
   " Movie path: A string to the path of your movie (in my example it's "myFlashMovie.swf")
   " Name: The title of your movie - not that important actually (in my example it's "Movie")
   " Width: The width of your movie as a string ("723" in my example)
   " Height: The height of your movie as a string ("600" in my example)
   " Version: The Flash Player version required to play the movie, again as a string ("8" in this example)
   " Background color: The background color to use... ("#FFFFFF", white in my example)
3. After the declaration of the initial values of our movie, we can add them some variables to play with in our Flash movie, that's accomplished with the addVariable() method.
   In my example, I'm creating a variable named currentPage and giving it a value of "aboutUs". You can add as many variables as you wish.
4. In the end, we write the Flash movie in the browser with the write() method.

Ok... so that's it for the HTML part, now let's move on to the Flash part.

The currentPage variable will exist in the _root of your movie. From there you can do simple things like check on the first frame the value of the variable and from there... do something like gotoAndPlay(); or whatever you choose to do. Mind you, you won't be able to test it on the Flash environment unless you create the variable for testing purposes and then delete it (otherwise this won't work).

Let's say that we'll go to different frames of the movie depending on the value of currentPage. If so; we'd do something like this:

// ActionScript - Frame 1

if(currentPage=="aboutUs") {
   gotoAndPlay(10);
} else if(currentPage=="index") {
   gotoAndPlay(15);
} else if(currentPage=="differentThings") {
   gotoAndPlay(20);
} else {
   //do nothing
}

Something along these lines will do the trick. If you need further assistance, please let me know.

-V
<HTML>

<HEAD>

<TITLE>My Webpage</TITLE>

<script type="text/javascript" src="./swfobject.js"></script>

</HEAD>

<BODY>

<div id="flashcontent">

      <p>Here you type your normal html if the user doesn't have Flash Player installed. It can be a table or whatever.</p>

</div>

<script type="text/javascript">

      // <![CDATA[

      var so = new SWFObject("myFlashMovie.swf", "Movie", "723", "600", "8", "#FFFFFF");

      so.addVariable("currentPage","aboutUs");

      so.write("flashcontent");

      // ]]>

</script>

</BODY>

</HTML>

Open in new window

0
 

Author Closing Comment

by:willnjen
ID: 31470031
Hi Vulturous

So sorry I didn't get back to the this earlier.  Thanks for your brilliant answer!!

Will
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now