Solved

Listening for javascript sent variable to flash

Posted on 2004-10-17
6
256 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Text To Speech Reader For Adobe Flash Pages 4 879
File drag and drop 6 131
Flash content not working in IE 11 on Windows 8.1 3 155
Shockwave Flash Object within PowerPoint 2013 2 114
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to record live broadcast.
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.

911 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

25 Experts available now in Live!

Get 1:1 Help Now