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

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 ;)
LVL 11
acsevenAsked:
Who is Participating?
 
muso120999Connect With a Mentor Commented:
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
 
apg88Commented:
This link says it all(with javascript). http://www.iota-six.co.uk/html/32_flash.htm
0
 
acsevenAuthor Commented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
apg88Commented:
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
 
muso120999Commented:
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
 
muso120999Commented:
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
 
acsevenAuthor Commented:
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
 
muso120999Commented:
> 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
 
acsevenAuthor Commented:
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
 
muso120999Commented:
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
 
acsevenAuthor Commented:
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
 
muso120999Commented:
Okay, I'll revise the code for you this evening.
0
 
acsevenAuthor Commented:
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
 
muso120999Commented:
>  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
 
acsevenAuthor Commented:
thanks! ;)
0
 
acsevenAuthor Commented:
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
 
muso120999Commented:
okay
0
 
acsevenAuthor Commented:
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
 
acsevenAuthor Commented:
I continued my html menu-to-flash creation here:
http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_21171821.html

thanks
0
 
muso120999Commented:
> you probably tested it, it works! thank you very much!

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

Glad to help!

muso
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.