how to make imported data from array update in AS3.0/Flex?
I think I must be missing a step here; I have different data being pulled from an array created from xml depending on a variable (_currentTrackNum).. and the data changes if I set a different initial value for it; but if I change the variable once the program is initialized, none of the data changes even though I rerun the call with the changed variable.
<s:HTTPService id="playlistxml" url="playlist.xml" result="init(event)" fault="noData(event)" />
<fx:Script>
<![CDATA[
private var _currentTrackNum:int;
public var playlistdata:ArrayCollection = new ArrayCollection();
public var locationarray:Array = new Array();
private function init(event:ResultEvent):void
{
playlistdata = event.result.playlist.track;
for (var i:Number=0;i<playlistdata.length;i++){
locationarray.push(playlistdata[i].location);
}
_currentTrackNum = 0;
_soundObj = new Sound();
_soundO开发者_开发技巧bj.load(new URLRequest(locationarray[_currentTrackNum]));
_soundChannel = new SoundChannel();
private function playSound():void
{
_soundChannel = _soundObj.play();
_isPlayingSound = true;
}
private function nextTrack():void
{
if(_currentTrackNum != locationarray.length()){
_currentTrackNum ++;
_soundObj.load(new URLRequest(locationarray[_currentTrackNum]));
}
}
I have tried with strings as well as sound objects so I know that the problem lies not with the handling of the soundchannel.
for reference, here is my xml structure:
<playlist>
<title>myplaylist</title>
<track>
<artist>The National</artist>
<title>Secret Meeting</title>
<location>http://localhost:8888/aim/Discography/uploads/4233019.mp3</location>
<album>Alligator</album>
<image>http://localhost:8888/aim/Discography/uploads/pics/alligator.jpg</image>
</track>
</playlist>
If you're using FlashBuilder , set a breakpoint just after playlistdata as been populated with the XML results, then look at the content of playlistdata. To do this , simply click the variables tab in the debug perspective .
A first guess would be that the results are not properly parsed and for some reason your Array may only contain one element or has been filled with the same element.
If playlistdata is properly populated , set another breakpoint later on in the process and you should find where it all breaks...
精彩评论