Example
The following example shows how a SWF file in a particular domain can invoke a method
named
in a receiving SWF file in the same domain.
printOut
First, create one SWF file with the following code:
this.createTextField("tf", this.getNextHighestDepth(), 10, 10, 300, 100);
var aLocalConnection:LocalConnection = new LocalConnection();
aLocalConnection.connect("demoConnection");
aLocalConnection.printOut = function(aString:String):Void{
tf.text += aString;
}
Then create a second with the following code:
var sending_lc:LocalConnection = new LocalConnection();
sending_lc.send("demoConnection", "printOut", "This is a message from file
B. Hello.");
To test this example, run the first SWF file, and then run the second one.
Here is another example. SWF 1 contains the following code, which creates a new Sound
object that plays back an MP3 file at runtime. A ProgressBar called
playback progress of the MP3 file. A Label component instance called
name of the MP3 file. Buttons in different SWF files will be used to control the playback
using a LocalConnection object.
var playback_pb:mx.controls.ProgressBar;
var my_sound:Sound;
playback_pb.setStyle("themeColor", "haloBlue");
this.createEmptyMovieClip("timer_mc", this.getNextHighestDepth());
var receiving_lc:LocalConnection = new LocalConnection();
receiving_lc.playMP3 = function(mp3Path:String, mp3Name:String) {
song_lbl.text = mp3Name;
playback_pb.indeterminate = true;
my_sound = new Sound();
my_sound.onLoad = function(success:Boolean) {
playback_pb.indeterminate = false;
};
my_sound.onSoundComplete = function() {
delete timer_mc.onEnterFrame;
};
timer_mc.onEnterFrame = function() {
playback_pb.setProgress(my_sound.position, my_sound.duration);
};
my_sound.loadSound(mp3Path, true);
};
receiving_lc.connect("lc_name");
displays the
playback_pb
displays the
song_lbl
LocalConnection
721
Need help?
Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?