Jump to content
Search Community

Array.push(event.target.content);

bonassus test
Moderator Tag

Recommended Posts

I'm loading Mp3 files with MP3Loaders and then using push(event.target.content) to store them in the array, notesArray. When I trace(notesArray); I get :

[object Sound],[object Sound],[object Sound],[object Sound],[object Sound],[object Sound],[object Sound],[object Sound],[object Sound],[object Sound],[object Sound],[object Sound]

 

so event.target.content is a sound object that contains the mp3?

 

But when i trace(notesArray[0]); I get:

undefined

 

Why? how can i access each sound object/ mp3 as an index of the array? what am i doing wrong?

 

here is the code:

 

 

 

package  {
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

public class NoteLoader {

		private var queue:LoaderMax;
		public var notesArray:Array = [];

		public var note2_A;
		public var note2_A_S;
		public var note2_B;
		public var note2_C;
		public var note2_C_S;
		public var note2_D;
		public var note2_D_S;
		public var note2_E;
		public var note2_F;
		public var note2_F_S;
		public var note2_G;
		public var note2_G_S;

	public function NoteLoader() {

		 queue = new LoaderMax({name:"mainQueue", onComplete:completeHandler});
			queue.append(note2_A = new MP3Loader("2_A.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_A_S = new MP3Loader("2_A#.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_B = new MP3Loader("2_B.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_C = new MP3Loader("2_C.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_C_S = new MP3Loader("2_C#.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_D = new MP3Loader("2_D.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_D_S = new MP3Loader("2_D#.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_E = new MP3Loader("2_E.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_F = new MP3Loader("2_F.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_F_S = new MP3Loader("2_F#.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_G = new MP3Loader("2_G.mp3", {autoPlay:false,estimatedBytes:25000 }) );
			queue.append(note2_G_S = new MP3Loader("2_G#.mp3", {autoPlay:false,estimatedBytes:25000 }) );

					queue.prependURLs("Notes/");
					 queue.load();
	}

	function completeHandler(event:LoaderEvent):void {
			notesArray.push(event.target.content);

			//	trace(notesArray[0]); undefined???????? 


	}

}

}

 

Thanks for any help!

Link to comment
Share on other sites

great question.

 

in your case event.target.content is an Array of all the content inside all the MP3 loaders inside your LoaderMax.

 

so you are putting an Array inside notesArray. You can trace that the length of notesArray after load is 1.

 

the content of an MP3Loader is a Sound() object. so you have an array of Sounds inside notesArray.

 

so you could do:

 

 function completeHandler(event:LoaderEvent):void {
         notesArray.push(event.target.content);


       trace(notesArray);
trace(notesArray.length);

       //play the first Sound object
notesArray[0][0].play();


     }

 

***EDIT*** just realized the main problem is you were using push(). you could really just do notesArray = event.target.content and you would be fine with notesArray[0] to get at the frist Sound object ***END EDIT***

 

 

you could also do it this way so that you have access to all the MP3Loader methods and properties

 

 function completeHandler(event:LoaderEvent):void {

       //getChildren() returns an Array of all the MP3Loaders
       notesArray = queue.getChildren();

//call playSound() on the first MP3Loader	
       notesArray[0].playSound();   


     }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...