Skip to main content
David_Beedle
Known Participant
November 20, 2008
Answered

Detecting button click from another SWF

  • November 20, 2008
  • 3 replies
  • 567 views
I need a starting point on how to go about scripting the following:

On an swf (original.swf), I have a movie clip (myMovieClip_mc), into which I load a second swf(second.swf). There is a button (myButton_btn) on second.swf.

While working in original.swf, I want to perform an action based on the button click of myButton_btn in second.swf.

What's the best way to go about doing this? (Just looking for a starting point...)

Thanks so much,
David
This topic has been closed for replies.
Correct answer robdillon
If the variable is on the loaded movie's root timeline, then the path to that variable is something like:
movieClipName.variableName

where movieClipName is the name of the empty clip that the new swf is loaded in to.

You want the button function to be in the same movie as the button. So, in the loaded swf, you could have something like:
var myToggle:Boolean = false;

myButton.onRelease = function() {
myToggle = !myToggle;
_parent.showValue();
}
The function changes the value of the boolean variable and then calls another function in the parent movie.

In the parent movie you will have another function like this:
function showValue() {
trace(holder.myToggle);
}
This function is called from the loaded swf. MyToggle is the variable in the loaded swf. Holder is the name of the empty movieClip that the movie is loaded in to.

3 replies

robdillon
robdillonCorrect answer
Participating Frequently
November 21, 2008
If the variable is on the loaded movie's root timeline, then the path to that variable is something like:
movieClipName.variableName

where movieClipName is the name of the empty clip that the new swf is loaded in to.

You want the button function to be in the same movie as the button. So, in the loaded swf, you could have something like:
var myToggle:Boolean = false;

myButton.onRelease = function() {
myToggle = !myToggle;
_parent.showValue();
}
The function changes the value of the boolean variable and then calls another function in the parent movie.

In the parent movie you will have another function like this:
function showValue() {
trace(holder.myToggle);
}
This function is called from the loaded swf. MyToggle is the variable in the loaded swf. Holder is the name of the empty movieClip that the movie is loaded in to.
David_Beedle
Known Participant
November 21, 2008
Simply awesome. Thanks so much.

David
robdillon
Participating Frequently
November 20, 2008
You could create a boolean variable in one of those movieClips and then change it's value when myButton is used. You can then get the value of the variable from original.swf.
David_Beedle
Known Participant
November 20, 2008
my original idea was to have an "onRelease" function in frame 1 of original.swf to detect the button click. The problem is I'm not sure what the pathway (represented by *********** in the code below) from myMovieClip_mc on original.swf to myButton_btn on second.swf is... or if that's even something that will work...

this.***********.onRelease = function() {
trace("myButton_btn in second.swf was clicked!");
// perform stuff
};


robdillon
Participating Frequently
November 20, 2008
You could create a boolean variable in one of those movieClips and then change it's value when myButton is used. You can then get the value of the variable from original.swf.
David_Beedle
Known Participant
November 20, 2008
How, exactly? I'm not sure how to retrieve that boolean variable value from the original.swf.

My inexperience is showing... sorry.