EasyManua.ls Logo

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE - Page 721

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
1378 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
LocalConnection 721
Example
The following example shows how a SWF file in a particular domain can invoke a method
named
printOut in a receiving SWF file in the same domain.
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_pb displays the
playback progress of the MP3 file. A Label component instance called
song_lbl displays the
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");

Table of Contents

Related product manuals