Solved

Listening for javascript sent variable to flash

Posted on 2004-10-17
6
263 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
[X]
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
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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 …
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 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 use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

622 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