Solved

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

Posted on 2004-10-08
20
2,968 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
Comment Utility
This link says it all(with javascript). http://www.iota-six.co.uk/html/32_flash.htm
0
 
LVL 11

Author Comment

by:acseven
Comment Utility
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
Comment Utility
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
 
LVL 10

Expert Comment

by:muso120999
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 10

Expert Comment

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

Author Comment

by:acseven
Comment Utility
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
Comment Utility
>  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
Comment Utility
thanks! ;)
0
 
LVL 10

Accepted Solution

by:
muso120999 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
okay
0
 
LVL 11

Author Comment

by:acseven
Comment Utility
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
Comment Utility
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
Comment Utility
> 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 Trending Threat Insights Every Day

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

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
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.

772 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

8 Experts available now in Live!

Get 1:1 Help Now