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
Solved

Control Flash SWF from HTML (and/or ASP) menu (providing vars)

Posted on 2004-10-08
20
2,972 Views
Last Modified: 2012-06-22
Hi,

  I am making a flash movie that has most the content (text, imgs, etc..) in the site I am building. This swf is included in a CSS based page, that has a menu (<a> tags, basically).

   As the content in the flash movie mentioned earlier is created "on the fly", using actionscript, I  want to know how to control the SWF movie using the html menu. I can tell you that I know how to make the html menu play/stop/gotoframe in the flash movie, so what I needed is something a bit different.

   What I want is to flash to pick up a click in the menu bar, and receive the click with a variable, so that flash can redirect that instruction to the specific funtion it'll have to make in the movie. So basically, here's an a example of one of the functions I'll need to implement:

 > click LINK1
 > send variable LINK1
 > flash receives LINK1
 > flash loads an SWF file named LINK1.swf onto a scrollpane.

I would very much appreciate *code* for this, all ASP/JS coding (this is very important, as I dunno almost nothing about those), and regarding the linkage of the variable to the import of the SWF file.

Important bit: the page couldn't refresh (mainly because I have other animations running that I don't want to break the animation at mid-play), hence the ASP...

also, this is kinda urgent.:S

thank you very much in advance ;)
0
Comment
Question by:acseven
  • 9
  • 9
  • 2
20 Comments
 
LVL 1

Expert Comment

by:apg88
ID: 12262654
This link says it all(with javascript). http://www.iota-six.co.uk/html/32_flash.htm
0
 
LVL 11

Author Comment

by:acseven
ID: 12264615
Hi, thanks for the link, but besides not answering fully to my question, the thing doesn't work using Firefox (JS doesn't make anything in the video, only in IE)... i need this to be cross-browser, obviously... :S

nice link though, thanks anyway ;)
0
 
LVL 1

Expert Comment

by:apg88
ID: 12267517
Yes, I noticed the firefox thing.
The problem with javascript is that it is different with every browser. Hopefully in one of the later builds of firecix, this will be fixed.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:muso120999
ID: 12267559
The problem basically is how the Flash object is being referenced, and, as far as I know, has always been a difference between Microsofts JScript, and NS/Mozilla's JavaScript.  Personally, I don't see this as a "bug" that will be fixed.

Basically IE accesses Flash via the "document" object, and NS/FireFox use the "window" object

Here is a slightly more comprehensive tutorial, with IE detection:
http://www.moock.org/webdesign/flash/fscommand/
0
 
LVL 10

Expert Comment

by:muso120999
ID: 12267564
As far as detecting when a variable has passed, I think you could use the Flash MX function Object.watch() which will trigger a function when the variable changes value
0
 
LVL 11

Author Comment

by:acseven
ID: 12282492
Hi again,

thanks for the link and ideas, but as I don't have much free time to look at this extensively, I looked around based on your suggestions [keywords], and found this tutorial:

http://www.mustardlab.com/developer/flash/jscommunication/

could you please tell me if u can implement this?  if successful, please explain a bit better on what is needed...

sorry for the trouble, but like I said, it is kinda urgent, and I am doing tons of other stuff at the same time...

thank you very much ;)
0
 
LVL 10

Expert Comment

by:muso120999
ID: 12292035
> could you please tell me if u can implement this?

It's perfectly implementable in so far as the tutorial you have found comes complete with a fully functional downloadable example (with source code).  What more do you need?
0
 
LVL 11

Author Comment

by:acseven
ID: 12292394
yes, you're right, I should have been more specific, I apologise:

The problem is that that example compiles just fine, but inserting the code in a project of mine (like the one in ex. movie.fla, code in first frame, included or not), I get execution errors, which I don't know why they occur in my fla and not in this one:

Quote:
_______________________
**Error** Scene=Scene 1, layer=actionscript, frame=1:Line 2: There is no property with the name '$jsvarlistener'.
Stage.$jsvarlistener = new LocalConnection();

**Error** Scene=Scene 1, layer=actionscript, frame=1:Line 3: There is no property with the name '$jsvarlistener'.
Stage.$jsvarlistener.setVariables = function(query) {

**Error** Scene=Scene 1, layer=actionscript, frame=1:Line 11: There is no method with the name '$jsvarlistener'.
Stage.$jsvarlistener.connect(_level0.movieid);

Total ActionScript Errors: 3 Reported Errors: 3
____________________________

sorry again :S






0
 
LVL 10

Expert Comment

by:muso120999
ID: 12292856
Hmm...  I take my last statement back - it isn't "perfectly implementable!"

The short answer to your problem now is to change the publish settings to ActionScript 1.0 rather than ActionScript 2.0, but that may effect other areas of your coding.

The long answer is explained here:
http://rantworld.blogs.com/flashlit/2003/12/quirks_of_dynam.html

Basically, the upshot is that your tutorial implements a dynamic variable assigned to LocalConnection - however, Macromedia in their wisdom, have now made the LocalConnection class non-dynamic.  This means that you can't just assign new values to it (which the tutorial uses).

Of the two solutions, probably the better one is to define a dynamic sub-class rather than to amend the LocalConnection class provided with Flash MX 2004 (this seems to me like a hack, and something that may have unforseen implications in the future).

With this in mind, how do you now want to move things forward acseven?
0
 
LVL 11

Author Comment

by:acseven
ID: 12292948
thanks muso, the answer should lie somewhere.. :D

well, truth is that I don't know that much scripting to understand how to do that, or how to even start understanding how to do it.. and right now I haven't got time to look at this as I really would like to...

If you could help me out only with this code revision, it would be great, because I have already made the rest of the scripting in the flash movie, being this part (receiving the variables) the only thing left ...

either way, thank you very much for help until now ;)

0
 
LVL 10

Expert Comment

by:muso120999
ID: 12295488
Okay, I'll revise the code for you this evening.
0
 
LVL 11

Author Comment

by:acseven
ID: 12317149
Hi, sorry to bother, but any luck with the revising?

if not, or if too much trouble, I'll try to do a local connection, replacing the HTML menu by a flash menu...

thank you ;)
0
 
LVL 10

Expert Comment

by:muso120999
ID: 12317169
>  Hi, sorry to bother, but any luck with the revising?

I'm terribly sorry!  I hadn't forgotten - just got a bit overloaded with other work :-(

I promise that I will have something tonight - and don't worry, it isn't too much trouble at all!

muso
0
 
LVL 11

Author Comment

by:acseven
ID: 12318348
thanks! ;)
0
 
LVL 10

Accepted Solution

by:
muso120999 earned 500 total points
ID: 12323250
Actually, it's a pretty quick fix - just use this code instead of the supplied code...

// -----------------------------------------------------------
// Univeral method for javascript->flash setvariable
// -----------------------------------------------------------
if(!_level0["$jslisten_init"]){
      Stage["$jslisten_init"] = new LocalConnection();
      Stage["$jslisten_init"].setVariables = function(query) {
            var i, values;
            var chunk = query.split("&");
            for (i in chunk) {
                  values = chunk[i].split("=");
                  _root[values[0]] = values[1];
            }
      };
      Stage["$jslisten_init"].connect(_level0.movieid);
      _level0["$jslisten_init"] = true;
}
domain = Stage["$jslisten_init"].domain();
stop();
0
 
LVL 11

Author Comment

by:acseven
ID: 12326726
hi, thanks for the code, I'll implement on the weekend. I will be away, but I'll let you know smtg on sunday night or monday ;)
0
 
LVL 10

Expert Comment

by:muso120999
ID: 12328420
okay
0
 
LVL 11

Author Comment

by:acseven
ID: 12334853
you probably tested it, it works! thank you very much!

I now have another problem, but I guess it's best to open a new question for this one ;)=

thanks again for your help ;)
0
 
LVL 11

Author Comment

by:acseven
ID: 12334904
I continued my html menu-to-flash creation here:
http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_21171821.html

thanks
0
 
LVL 10

Expert Comment

by:muso120999
ID: 12336718
> you probably tested it, it works! thank you very much!

I usually do (unless otherwise specified); saves embarassment ;-)

Glad to help!

muso
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Action Script commands 3 220
blocked plugin flash 5 121
bandwidth 5 76
What is needed to center a flash image to the center of the page? 4 103
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

828 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