Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Flash reads param from html

Posted on 2008-06-23
3
Medium Priority
?
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

636 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