Results 1 to 14 of 14
Thread: Error 1136... calling URLLoader
-
May 11th, 2012, 01:07 PM #110Registered User
postsError 1136... calling URLLoader
Hey guys... I'm getting a strange error and I'm not quite sure why. It's Error 1136: Incorrect number of arguments. Expected 1. I attached my .fla and .xml files. On my machine I have a folder labelled "audio" in the same folder as my project files.
Here's my code:
Any ideas??Code:import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.Event; import flash.media.Sound; import flash.media.SoundChannel; //variables for the songs list var my_songs:XMLList; var my_total:Number; //sound class variables var my_sound:Sound; var my_channel:SoundChannel; var current_song:Number = 0; var song_position:Number; var song_paused:Boolean; //THIS IS WHERE I GET MY ERROR //Error 1136: Incorrect number of arguments. Expected 1. var myXMLLoader:URLLoader = URLLoader(); myXMLLoader.load(new URLRequest("playlist.xml")); myXMLLoader.addEventListener(Event.COMPLETE, processXML); //function to process the playlist file function processXML(e:Event):void { var myXML:XML = new XML(e.target.data); my_songs = myXML.SONG; my_total = my_songs.length(); //playSong(0); //uncomment to have it play automatically when it loads myXMLLoader.removeEventListener(Event.COMPLETE, processXML); myXMLLoader = null; } //function to play a song -- @ sign is for Flash to get attributes of an XML node function playSong(mySong:Number):void { var myTitle = my_songs[mySong].@TITLE; var myArtist = my_songs[mySong].@ARTIST; var myURL = my_songs[mySong].@URL; title_txt.text = myTitle; artist_txt.text = myArtist; if (my_channel) { my_channel.stop(); my_channel.removeEventListener(Event.SOUND_COMPLETE, onNext); } my_sound = new Sound(); my_sound.load(new URLRequest(myURL)); my_channel = my_sound.play(); my_channel.addEventListener(Event.SOUND_COMPLETE, onNext); } next_btn.addEventListener(MouseEvent.CLICK, onNext); function onNext(e:Event):void { current_song++; if (current_song >= my_total) { current_song = 0; } playSong(current_song); } prev_btn.addEventListener(MouseEvent.CLICK, onPrev); function onPrev(e:MouseEvent):void { current_song--; if (current_song < 0) { current_song = my_total - 1; } playSong(current_song); } pause_btn.addEventListener(MouseEvent.CLICK, onPause); function onPause(e:MouseEvent):void { if (my_channel) { song_position = my_channel.position; my_channel.stop(); song_paused = true; } } play_btn.addEventListener(MouseEvent.CLICK, onPlay); function onPlay(e:MouseEvent):void { if (song_paused) { my_channel = my_sound.play(song_position); song_paused = false; } else if (!my_channel) { playSong(current_song); } }
-
May 11th, 2012, 01:40 PM #2881zzz
postsit isnt creating a new URLLoader
should be:
var myXMLLoader:URLLoader = new URLLoader();instead of
var myXMLLoader:URLLoader = URLLoader();
-
May 11th, 2012, 02:55 PM #310Registered User
postswow... I think that's one of the dumbest mistakes I've made.
Now I am getting a TypeError though.

TypeError: Error #1090: XML parser failure: element is malformed.
at DavidsonD_Exercise7_fla::MainTimeline/processXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
This is my XML code since I didn't post it earlier:
Code:<?xmlversion="1.0"encoding="UTF-8"?><PLAYLIST> <SONG URL="audio/track1.mp3" TITLE=""Stockholm Syndrome" ARTIST="Muse" /> <SONG URL="audio/track2.mp3" TITLE="Supermassive Black Hole" ARTIST="Muse" /> <SONG URL="audio/track3.mp3" TITLE="Knights of Cydonia" ARTIST="Muse" /> <SONG URL="audio/track4.mp3" TITLE="Muscle Museum" ARTIST="Muse" /> </PLAYLIST>
-
May 11th, 2012, 05:43 PM #4881zzz
postsHa ha ha, those are the best ones since they are so easy to fix! It just needs a new pair of eyes to spot them.
Try something like this:
I think its to do with spacing between the attributes that was breaking it before.Code:<?xml version="1.0" encoding="UTF-8"?> <PLAYLIST> <SONG URL ="audio/track1.mp3" TITLE="Stockholm Syndrome" ARTIST="Muse"> </SONG> <SONG URL ="audio/track2.mp3" TITLE="Supermassive Black Hole" ARTIST="Muse"> </SONG> </PLAYLIST>
-
May 11th, 2012, 06:51 PM #510Registered User
postsThanks again for your help.
I changed my XML document to match the style you posted, but I am still receiving the same error. This is my first real go with using XML, so I really have no idea what might be wrong. Is there an easier way to achieve what I am trying to get or is there something I'm just missing?
-
May 11th, 2012, 07:22 PM #6881zzz
postsIf you copy the example I posted and add any others in the same format it should be fine
Its to do with the white space I think, Im no expert but I think its just a formatting thing.
-
May 11th, 2012, 09:54 PM #710Registered User
postsOkay, I see what you mean now. I did not realize that spacing was that important when typing up an XML document. It works perfectly now.

Would you have any idea how to make a shuffle button work so that it would pick a random song to play if the shuffle button has been clicked?
-
May 11th, 2012, 10:03 PM #8881zzz
postsvar pickTrack:int = Math.round(Math.random()*numSongs)
playTrack[pickTrack];
so just get a random number based on the number of songs then you can pick the data out of your XML object using the pickTrack var, you can look at this for reference when using simple sounds and get an idea of how to load the sound and play it.
the sound player is a great way to learn as3.0.
-
May 11th, 2012, 11:14 PM #910Registered User
postsI get what you are saying but I'm having some trouble placing the code into my fla. This is what I have, but I just think I am getting confused since I am unfamiliar with using sound in flash:
I know I have to define numSongs, but I am not sure what to put.Code:rdm_btn.addEventListener(MouseEvent.CLICK, playTrack); function playTrack(e:MouseEvent):void { var pickTrack:int = Math.round(Math.random() * numSongs) playTrack[pickTrack]; }
Thanks for taking time to help me btw!
-
May 12th, 2012, 02:17 AM #10881zzz
postsIve had so much help from these forums it took a while but I can finally start helping a few people.
to play the actual mp3s you should use
http://www.republicofcode.com/tutorials/flash/as3sound/
I find breaking it down like this helps me:
1.load XML
2.set an index (pickTrack)
3.find sound file url string from XML object (myXML.song[pickTrack].URL)
4.load sound file using the republic of code tutorial
5.play sound file
numSongs = myXML.length so it would be the number of songs in your xml
This is a great exercise for learning as3.
-
May 12th, 2012, 01:27 PM #1110Registered User
postsI figured it out! It took me a while and then I had my aha! moment. Thank you for that link... It definitely got me going in the right direction. Only problem is I need to set a limit because it calculates a number greater than the number of songs in the list.
This is what I ended up doing:
Last thing to add is a button for each song so you can click on each individual song and play it.Code:var current_song:Number = 0 rdm_btn.addEventListener(MouseEvent.CLICK, playTrack); function playTrack(e:MouseEvent):void {current_song = Math.round(Math.random() * my_total); playSong(current_song); }
-
May 12th, 2012, 01:48 PM #12881zzz
poststry replace Math.round with Math.floor.
my_total should be the length of the myXML nodes
-
May 12th, 2012, 03:35 PM #1310Registered User
postsGot it. Thanks for your help. I thought you might like to see the finished product.
XML Music Player
I want to try and add some volume controls next.
-
May 12th, 2012, 09:39 PM #14881zzz
postsits dead easy to get all the bells and wistle on, you mind find the computeSpectrum method of SoundMixer class fun.
http://help.adobe.com/en_US/FlashPla...puteSpectrum()

Reply With Quote


Bookmarks