Ultrashock Forums > Flash > ActionScript
how to correct this; TypeError: Error #2007: Parameter sound must be non-null.

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
how to correct this; TypeError: Error #2007: Parameter sound must be non-null.
Old 2008-01-17

hi everybody.


I'm very new to class'es, and still bumping into crazy errors.
in my recent project, I get this error over and over again:
TypeError: Error #2007: Parameter sound must be non-null.

my project is a class, that not only plays a .mp3, but visualizes it at the same time.
to do this, I've written this in my .fla:
Code:
stop();

//set up the VisualizeMusic class
import VisualizeMusic;
var visualizemusic:VisualizeMusic = new VisualizeMusic();
addChild(visualizemusic);
// now the stage property of the class is no longer null

//music, number of times to loop
visualizemusic.init("vibe_music.mp3", 9999);
and the following in my .as-file:
Code:
package {

	import flash.display.Sprite;
	import flash.media.Sound;
	import flash.media.SoundMixer;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	import flash.events.Event;
	//import flash.text.TextField;
	
	public class VisualizeMusic extends Sprite {
		
		private var theMusic:String;
		private var numberOfLoops:Number;
		private var bytearray:ByteArray;
		
		public function VisualizeMusic() {
			trace("function VisualizeMusic");
		}
		
		public function init(music:String, numLoops:Number):void {
			theMusic = music;
			numberOfLoops = numLoops
			trace("VisualizeMusic initiated");
			var bytearray:ByteArray = new ByteArray();
			var mysound:Sound = new Sound(new URLRequest(theMusic));
			addEventListener(Event.ENTER_FRAME, doTheGraphics);
			mysound.play(0, numberOfLoops);
			
		}
		
		private function doTheGraphics(event:Event):void{
			trace("function doTheGraphics");
			var myVisualizer:Sprite = new Sprite();
			myVisualizer.graphics.clear;
			myVisualizer.graphics.lineStyle(1, 0xFFFFFF);
			myVisualizer.graphics.moveTo(0, 50);
			SoundMixer.computeSpectrum(bytearray);
			for(var i:uint = 0; i<256; i++){
				//the readFloat reads the next value in the ByteArray and assigns it to a Number
				var num:Number = bytearray.readFloat()*40 + 50;
				myVisualizer.graphics.lineTo(i*.4, num);
			}
		}
	}
}

it seems kinda straightahead to me.
the init function sets up the sound and plays it, and the eventListener fires the doTheGraphics-function.
but somethings is not done correctly, I just can't figure out what...


can anyone help me?
thanks
felisan
---------------------------------------------
http://www.campjohn.dk/wp/
postbit arrow 7 comments | 4983 views postbit arrow Reply: with Quote   
Registered User
felisan is offline
seperator
Posts: 234
2005-02-18
Age: 33
felisan lives in Denmark
seperator

Ultrashock Member Comments:
Rackdoll's Avatar Rackdoll Rackdoll is offline Rackdoll lives in Netherlands 2008-01-17 #2 Old  
i think if you dont push the URLRequest right away in the SOund it should be fine.
Just make a soundObject and do not pass a URLRequest in it...
Then just play or load the URLRequest..
Reply With Quote  
felisan felisan is offline felisan lives in Denmark 2008-01-17 #3 Old  
hi Rackdoll.

I'm not sure what you mean...
I've tried this:
Code:
var mysound:Sound = new Sound;
mysound(new URLRequest(theMusic));

but that doesn't help.
what did you mean?


thanks
felisan
Reply With Quote  
felisan felisan is offline felisan lives in Denmark 2008-01-17 #4 Old  
please, can anyone help?
Reply With Quote  
-Loren- -Loren- is offline -Loren- lives in United States 4 Creative Assets 2008-01-17 #5 Old  
Hi!,

I made a few modifications to your code, but everything is working now

Here is the new code, I will explain some of my changes below:

ActionScript Code:
  1. package {
  2.  
  3.     import flash.display.Sprite;
  4.     import flash.media.Sound;
  5.     import flash.media.SoundMixer;
  6.     import flash.net.URLRequest;
  7.     import flash.utils.ByteArray;
  8.     import flash.events.Event;
  9.     //import flash.text.TextField;
  10.    
  11.     public class VisualizeMusic extends Sprite {
  12.        
  13.         private var theMusic:String;
  14.         private var numberOfLoops:Number;
  15.         private var bytearray:ByteArray = new ByteArray();
  16.         private var mysound:Sound = new Sound();
  17.         private var myVisualizer:Sprite = new Sprite();
  18.         public function VisualizeMusic() {
  19.             trace("function VisualizeMusic");
  20.         }
  21.        
  22.         public function init(music:String, numLoops:Number):void {
  23.             this.addChild(myVisualizer);
  24.             theMusic = music;
  25.             numberOfLoops = numLoops
  26.             trace("VisualizeMusic initiated");
  27.             var bytearray:ByteArray = new ByteArray();
  28.             mysound.load(new URLRequest(theMusic));
  29.             addEventListener(Event.ENTER_FRAME, doTheGraphics);
  30.             mysound.play(0, numberOfLoops);
  31.            
  32.         }
  33.        
  34.         private function doTheGraphics(event:Event):void{
  35.            
  36.             trace("function doTheGraphics");
  37.             myVisualizer.graphics.clear();
  38.             myVisualizer.graphics.lineStyle(1, 0xFFFFFF);
  39.             myVisualizer.graphics.moveTo(0, 50);
  40.            
  41.             SoundMixer.computeSpectrum(bytearray,true,0);
  42.             for(var i:uint = 0; i<256; i++){
  43.                 //the readFloat reads the next value in the ByteArray and assigns it to a Number
  44.                 var num:Number = bytearray.readFloat()*40 + 50;
  45.                 myVisualizer.graphics.lineTo(i*.4, num);
  46.             }
  47.            
  48.         }
  49.     }
  50. }

First thing I did was finish the constructor for ByteArray. Byte arrays need to be instantiated like a standard array, like this: var byteArray:ByteArray = new ByteArray(); (You had everything except the = new ByteArray() part).

I added your display sprite's declaration with your other private variables so it would only need to be referenced once throughout the visualizations. I also added this.addChild(myVisualizer); to your init, so that the content being drawn within that sprite would be visible to the user.

I moved your Sound constructor with your other private variables, again, to make it a global reference.

I completed your clear function inside your doTheGraphics function. You just didn't have parenthesis after clear, as in clear();

I removed the new constructor from your myVisualizer sprite since in this case, reinstantiating myVisualizer would cause your system to get very bogged down with that many sprites being referenced in the application.

I hope this helps, let me know if anything else arises.
Reply With Quote  
felisan felisan is offline felisan lives in Denmark 2008-01-17 #6 Old  
ok.
- you corrected ByteArray and clear.
- you added the displaySprite to the displaylist, making it visible.
- then you listed Sound and displaySprite among the other private variables for quicker future reference.
- and finally you removed the instantiation of the displaySprite for better flow.

correct?

thanks.
you have helped me very much owe you one!
felisan
Reply With Quote  
-Loren- -Loren- is offline -Loren- lives in United States 4 Creative Assets 2008-01-17 #7 Old  
Yep, I believe that was it Have fun, visualizations are a great thing to learn with.
Reply With Quote  
babbje babbje is offline babbje lives in United States 2010-02-08 #8 Old  
I need help. I have this action script here...and I keep getting that same error

TypeError: Error #2007: Parameter child must be non-null.
at flash.display:isplayObjectContainer/removeChild()
at DotDrawFull_startTryone_fla::MainTimeline/clearCanvas()

This is my action script. I believe the only thing wrong with it is at the bottom which states:
clear_btn.addEventListener(MouseEvent.CLICK, clearCanvas);

function clearCanvas (evt:MouseEvent): void {
var myDot_mc: MovieClip;
var numbDots:Number=dotArray.length;
for (var i:Number= 0; i<numbDots; i++)
myDot_mc=dotArray.pop();
canvas.removeChild(myDot_mc);
myDot_mc=null;
}

When I have this action script I should be able to press this button with a instance name clear_btn and the dots on the page should be "erased". I don't know what is going on. Here is the full action script

var currentColor:String= "green";
var dotArray:Array= new Array;

setGreen_btn.addEventListener (MouseEvent.CLICK,setGreenPencil);
setRed_btn.addEventListener (MouseEvent.CLICK, setRedPencil);
setBlue_btn.addEventListener (MouseEvent.CLICK, setBluePencil);

function setGreenPencil(evt:MouseEvent): void {
currentColor= "green";
}

function setRedPencil (evt:MouseEvent): void {
currentColor="red";
}

function setBluePencil(evt:MouseEvent): void {
currentColor="blue";
}

canvas.addEventListener (MouseEvent.MOUSE_DOWN, startDraw);

function startDraw (evt:MouseEvent): void{
canvas.addEventListener(MouseEvent.MOUSE_MOVE, drawShape);
canvas.addEventListener(MouseEvent.MOUSE_UP, stopDraw);
}

function drawShape (evt:MouseEvent): void{
var myDot_mc: MovieClip;
if (currentColor == "red") {
myDot_mc=new RedDot ();
} else if (currentColor == "blue") {
myDot_mc=new BlueDot();
} else {
myDot_mc=new GreenDot ();
}
myDot_mc.x=mouseX-canvas.x;
myDot_mc.y=mouseY-canvas.y;
dotArray.push (myDot_mc);
canvas.addChild(myDot_mc);
}

function stopDraw (evt:MouseEvent):void {
canvas.removeEventListener(MouseEvent.MOUSE_MOVE,drawShape);
canvas.removeEventListener(MouseEvent.MOUSE_UP, stopDraw);
}

clear_btn.addEventListener(MouseEvent.CLICK, clearCanvas);

function clearCanvas (evt:MouseEvent): void {
var myDot_mc: MovieClip;
var numbDots:Number=dotArray.length;
for (var i:Number= 0; i<numbDots; i++)
myDot_mc=dotArray.pop();
canvas.removeChild(myDot_mc);
myDot_mc=null;
}
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: