Stop sound of loaded SWFs in AS3
Posted by Helmut Granda | Filed under ActionScript, Programming
Until now I didn't have any issue when removing an item from the display list until the item had sound in it. This has to do with an application I am working on which loads several SWFs and they have to be turned "on" and "off". When the SWF has to be turned off the sound has to go with it. So having the item be removed from the DisplayList was the first "answer", but of course if every listener has to be removed from any item that is being removed from the DisplayList the sound object is not an exception. But how do you do that? Again the first logic was to add a new Sound object to the loaded SWF and then control the sound in that way but that didn't fly. Looking in the docs with more detail we find the SoundTransform and here is a description "The SoundTransform class contains properties for volume and panning. The following objects contain a soundTransform property, the value of which is a SoundTransform object: Microphone, NetStream, SimpleButton, SoundChannel, SoundMixer, and Sprite"
So with that knowledge in mind now we can control the sound of the loaded SWF's and here is a sample of what I was working with.
-
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
import flash.display.Loader;
import flash.utils.Timer;
import flash.media.SoundTransform;
public class SoundStopTest extends Sprite {
var loader1:Loader;
var loader2:Loader;
var mc1 : MovieClip;
var mc2 : MovieClip;
var holder:Sprite;
var mySoundTransform:SoundTransform
public function SoundStopTest() {
holder = new Sprite;
var url1:URLRequest=new URLRequest("scene6_portofino.swf");
var url2:URLRequest = new URLRequest("scene6_royalpacific.swf");
loader1=new Loader();
loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader1.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
loader1.load(url1);
loader2 = new Loader();
loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler2);
loader2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
loader2.load(url2);
holder.addChild(loader1);
holder.addChild(loader2);
addChild(holder);
var myTimer = new Timer(2500, 1)
myTimer.addEventListener("timer", theEvent)
myTimer.start();
var myTimer2 = new Timer(2500, 1)
myTimer2.addEventListener("timer", theEvent2)
myTimer2.start();
}
private function completeHandler (e:Event ) {
mc1 = MovieClip(loader1.content);
mc1.gotoAndPlay(2);
}
private function completeHandler2 (e:Event ) {
mc2 = MovieClip(loader2.content);
mc2.gotoAndPlay(2);
}
private function theEvent(e:TimerEvent) {
mySoundTransform = new SoundTransform();
mute();
}
private function theEvent2(e:TimerEvent) {
// holder.removeChild(loader1); Uncomment if you want control of one item instead of all
// holder.removeChild(loader2); Uncomment if you want control of one item instead of all
removeChild(holder);
}
function mute():void {
mySoundTransform.volume = 0;
// mc1.soundTransform = mySoundTransform; Uncomment if you want control of one item instead of all
// mc2.soundTransform = mySoundTransform; Uncomment if you want control of one item instead of all
holder.soundTransform = mySoundTransform;
}
private function ioErrorHandler(event:IOErrorEvent):void { }
}
}
One thing that you will notice is that I muted two movies at once by adding two movies into one item and then controlling the volume of that single item. The reason why am I doing it this way is because I need control of one movie at the time as also control of all movies together.
Another thing you will notice is a Timer Event, that was just added to enhance my testing but doesn't have to be used in this way.
//Flash Player with C++ Support
Posted by Helmut Granda | Filed under videos
Scott Peterson shows Flash on C/C++ sneak peek at Adobe MAX Chicago
//Google Android
Posted by Helmut Granda | Filed under videos
Sergey Brin and Steve Horowitz discuss the availability of the SDK, that it will be open source in the future, and demo some applications.
//Experience Adobe Acrobat 8
Posted by Helmut Granda | Filed under Recognition
I got a link of this site over email and to be honest I was impressed to see how Adobe used Flash and Video to showcase their latest version of their Acrobat product.
//Error #1063 When loading XML
Posted by Helmut Granda | Filed under ActionScript, Programming
If you get the following error when loading XML and trying to get the node attribute: ArgumentError: Error #1063: Argument count mismatch. It could be that you typed attributes instead of attribute.
//DescribeType for AS 3.0
Posted by Helmut Granda | Filed under ActionScript, Programming
Use describeType rather than a for-loop to enlist an object properties.
//Get The Glass
Posted by Helmut Granda | Filed under Recognition
Time to get the glass and play a game!
//Force close and open disk tray Mac
Posted by Helmut Granda | Filed under AS Burst
In a new command line type - drutil tray eject - to eject the disk or open a stuck tray. Type - drutil tray close - to close it.
//Flash Player 10 in Action
Posted by Helmut Granda | Filed under videos
//Convert milliseconds to seconds
Posted by Helmut Granda | Filed under Programming
( milliseconds / 1000 ) % 60