The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 14 of 14

Thread: Error 1136... calling URLLoader

  1. #1

    Error 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:

    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);
    	}
    }
    Any ideas??
    Attached Files Attached Files

  2. #2
    it isnt creating a new URLLoader

    should be:

    var myXMLLoader:URLLoader = new URLLoader();instead of
    var myXMLLoader:URLLoader = URLLoader();

  3. #3
    wow... 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>

  4. #4
    Ha 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:
    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>
    I think its to do with spacing between the attributes that was breaking it before.

  5. #5
    Thanks 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?

  6. #6
    If 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.

  7. #7
    Okay, 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?

  8. #8
    var 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.

  9. #9
    I 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:
    Code:
    rdm_btn.addEventListener(MouseEvent.CLICK, playTrack);
    function playTrack(e:MouseEvent):void {
        var pickTrack:int = Math.round(Math.random() * numSongs)
        
        playTrack[pickTrack];
    }
    I know I have to define numSongs, but I am not sure what to put.

    Thanks for taking time to help me btw!

  10. Ive 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.

  11. #11
    I 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:
    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); }
    Last thing to add is a button for each song so you can click on each individual song and play it.

  12. try replace Math.round with Math.floor.

    my_total should be the length of the myXML nodes

  13. #13
    Got 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.

  14. its 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()

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012