Solved

Listening for javascript sent variable to flash

Posted on 2004-10-17
6
258 Views
Last Modified: 2012-06-27
Hi,

 I have recently posted a question here (http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_21161353.html), that muso answered just right.

 To sum it up, I can send a variable to flash, and display it, i.e. on a text box. What I am building is a page with a flash movie and with an HTML menu.

 How can I make it run a given flash function upon clicking on each one of the html links? I have a function that loads an html file onto a text box, and I want to specify which html file to load, upon reception of the variable...

 I can't seem to find how to "listen" for the variable change...

 thanks in advance


ps: this is a bit urgent

0
Comment
Question by:acseven
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:muso120999
ID: 12336736
Did  you check out the help on Object.watch, that I mentioned in the previous question?...

> 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

It is a means of "listening" to a variable, and triggering a response when it changes!

muso
0
 
LVL 10

Accepted Solution

by:
muso120999 earned 500 total points
ID: 12336997
An example:

var test = "";
function fnCallBack(prop, oldVal, newVal) {
      trace(this);
      trace(prop+" changed from '"+oldVal+"' to '"+newVal+"'");
}
_root.watch("test",fnCallBack);


"test" is the variable being watched in this case.

muso
0
 
LVL 11

Author Comment

by:acseven
ID: 12338042
Hi again!

I really had forgotten you mentioned that on the other question. Even so, I still am not being able to get this working.. :S


I'll put some of my code here (all code is on the 1st frame of the movie). Code before this one loads the initial html and css files onto the textcontent textbox, no problems. All vars have been defined earlier, also:

_____________________
function changeHTML(fileName, filePath) {
      story = new XML();
      story.ignoreWhite = true;
      story.load(filePath+fileName);
      story.onLoad = function(ok) {
            textcontent.htmlText = story;
            if (ok) {
                  trace("changeHTML: "+fileName+" content loaded.");
            } else {
                  textcontent.htmlText = "ChangeHTML Error: Content not loaded. Please contact sys admin.";
            }
      }
      checking.htmlText = "trying to change ... "; // test text box. to remove
}

// execute functions, etc.

fscommand("showmenu", false);
if ((loadContentType == "htmlInclude") && (hmtlFileName !== "")) {
      htmlFileName = "inicio_pt.asp"; // to be changed.
      loadHtmlAndCSS(cssFileName, curLanguage, htmlFilePath, htmlFileName);
      trace("Ok! Loaded HTML and CSS.");
} else if (loadContentType == "swfInclude") {
      createScrollPaneAndLoadSWF(curLanguage, swfFilePath, swfFileName);
      trace("Ok! Loaded Flash SWF.");
} else {
      trace("ERROR!!");
}
var htmlFileNameSent:String = "";
if (htmlFileNameSent !== "") {   // if I don't put this here, it runs the fuction below. either way, it still doesn't load when clicked...
      _root.watch("htmlFileNameSent",changeHTML(htmlFileNameSent, htmlFilePath));
}
_______________________

when clicking on an <A> tag (link) the variable is received by flash (I have test textboxes that change when clicked), but it does not execute the .watch()....

what am I doing wrong?

thanks
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.

 
LVL 10

Expert Comment

by:muso120999
ID: 12338150
look at my example - your syntax is different!

Change:
     _root.watch("htmlFileNameSent",changeHTML(htmlFileNameSent, htmlFilePath));
to:
     _root.watch("htmlFileNameSent",changeHTML);

Note: By including brackets after changeHTML, you are actually executing it, and using tha return value as a parameter which doesn't make sense here, as the parameter expected is a refrerence to a function.

and:
  function changeHTML(fileName, filePath) {
to:
  function changeHTML(prop, oldVal, newVal) {

You should be able then to refer to _root.fileName and _root.filePath in the changeHTML function - assuming they are changed at the same time as htmlFileNameSent
0
 
LVL 11

Author Comment

by:acseven
ID: 12338345
yeah, I changed what should be kept unchanged... :P well,  it now works! everything is loading just fine, thanks once more ;)

ac7
0
 
LVL 10

Expert Comment

by:muso120999
ID: 12342280
No problem ;-)

muso
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
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 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 select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

790 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