Solved

Listening for javascript sent variable to flash

Posted on 2004-10-17
6
255 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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.

706 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

20 Experts available now in Live!

Get 1:1 Help Now