Maybe I'm wrong, but I don't think DisplayObject works like that. You
could create a new DisplayObject, but I don't think DisplayObject(param)
does anything. I think you're either creating a new DisplayObject or
creating a null object, and either way, it's not going to be a child of
your mySpectrum Sprite.
removeChild(event.target)
should be adequate, but if target needs a little help to know what to be
you can do this:
removeChild(event.target as DisplayObject) or removeChild(event.target
as Sprite)
Again, maybe I'm wrong, but that's my understanding
Bieniasz, Myles wrote:
I'm just starting to fool around with as3 and having a little fun with
computeSpectrum. I keep getting an error when I try to removeChild.
I'm using the Flash CS3 trial and setting the document class to
mySpectrum. Any help/explanation would be greatly appreciated. Thanks
in advance
Here's my script:
package{
import flash.display.*;
import flash.media.*;
import flash.net.*;
import flash.utils.*;
import flash.events.*;
import flash.display.Stage;
public class mySpectrum extends Sprite{
private var _s:Sound;
private var _sc:SoundChannel;
private var _ba:ByteArray = new ByteArray();
public function mySpectrum(){
stage.frameRate = 31;
_s = new Sound();
_s.load(new
URLRequest("bad_plus.mp3"));
_sc = _s.play(0,1000);
addEventListener(Event.ENTER_FRAME,
get_spectrum);
}
private function get_spectrum(event:Event):void{
SoundMixer.computeSpectrum(_ba,true,0);
graphics.clear();
graphics.lineStyle(1,0xffffcc,100);
var amp:Number = 0;
for(var i:uint = 0; i<512; i++){
var level:Number =
_ba.readFloat();
amp += level;
}
graphics.drawCircle(stage.stageWidth/2,stage.stageHeight/2,amp);
if(amp > 50){
drawBurst(amp);
}
}
private function drawBurst(burst:Number):void{
var burst_sprite:Sprite = new
Sprite();
burst_sprite.graphics.lineStyle(1,0xffffcc,(burst*.01));
burst_sprite.graphics.beginFill(0xffffcc,(burst*.01));
burst_sprite.graphics.drawCircle(Math.random() * stage.stageWidth,
Math.random() * stage.stageHeight, burst);
addChild(burst_sprite);
burst_sprite.addEventListener(Event.ENTER_FRAME, fade_out);
}
private function fade_out(event:Event):void{
event.target.alpha -=.05;
if(event.target.alpha <.1){
removeChild(DisplayObject(event.target));
}
}
}
}
And here's the error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child
of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at mySpectrum/::fade_out()
Myles Bieniasz
MLB Advanced Media
212.485.6129
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
************************
MLB.com: Where Baseball is Always On
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com