Solved

Listening for javascript sent variable to flash

Posted on 2004-10-17
6
259 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

713 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