Copy link to clipboard
Copied
:Vector.<String> not working when getting information with JSON from php file. I think my issue might be with the variable "something", tried a few hours with different ways. Nothing working so far.
Okay, so I am trying to implement Database.
This is the new code with the new bgmList,
var json:URLLoader = new URLLoader();
var parsedJSONData:Object;
json = new URLLoader();
json.addEventListener(Event.COMPLETE, parseJSON);
json.load(new URLRequest("http://blogglista.no/TESTESTDBDBDBDBD/check_media.php"));
trace("Loading JSON file...");
function parseJSON(evt:Event):void {
trace("JSON file loaded successfully!");
trace("Parsing JSON...");
trace("RESULTS:");
parsedJSONData = JSON.parse(json.data)
//trace(parsedJSONData.streams[0])
var i=0;
var something:String="";
for (i=0;i<3;i++){
something +=parsedJSONData.streams+ ","
;
}
something= something.substring( 0, something.length - 1 );
var bgmList:Vector.<String> = new <String>
[
something
];
trace(bgmList);
This is the old and working bgmList:
var bgmList:Vector.<String> = new <String>
[
"http://lyd.nrk.no/nrk_radio_p1_ostlandssendingen_mp3_h", //sound0 NRK P1
"http://stream.p4.no/p4_mp3_mq",//sound1 P4
];
trace(bgmList);
I get excact same when tracing both:
But I get an error with the new code,
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at Function/AdmobRadiotest_fla:MainTimeline/parseJSON/AdmobRadiotest_fla:playSound()[AdmobRadiotest_fla.MainTimeline::frame1:172]
at Function/AdmobRadiotest_fla:MainTimeline/parseJSON/AdmobRadiotest_fla:changeSound()[AdmobRadiotest_fla.MainTimeline::frame1:144]
at Function/AdmobRadiotest_fla:MainTimeline/parseJSON/AdmobRadiotest_fla:onMouse()[AdmobRadiotest_fla.MainTimeline::frame1:118]
All frames refering to bgmList in some way
var bgmList=new Vector.<String>();
for each (var data:Object in parsedJSONData.streams){//(i=0;i<parsedJSONData.streams.length;i++){
bgmList.push(data);
}
This soled my problems.
Thank you for helping kglad!
Have a nice sunday
Copy link to clipboard
Copied
what code are you using and what line of that code is triggering the error?
what you showed wouldn't even compile so it's not clear what you're doing based on what you've shown, so far.
Copy link to clipboard
Copied
Thank you for your comment. My full code is several hundred lines. Everything works just fine, until I replace the "bgmList".
When I trace the new bgmList it looks just like the other, excact. So I am assuming it somehow is the format of the String/Vector.
I added quotation marks to my bgmList now, on each side of the URL. I get other errors:
something += "\"" +parsedJSONData.streams + "\"" + ",";
What happens when I push my first sound button now:
SecurityError: Error #2147: Forbidden protocol in URL "http://lyd.nrk.no/nrk_radio_p1_ostlandssendingen_mp3_h","http://stream.p4.no/p4_mp3_mq","http://stream2.sbsradio.no/radionorge.mp3?ua=WEB&amsparams=playerid%3ASBS_RP_WEB%3Bskey%3A1428855822...",.
at flash.media::Sound/_load()
What happens when I click my second sound button now:
RangeError: Error #1125: The index 1 is out of range 1.
What happens when i remove the quotation marks in the bgmList I get this error when clicking my first sound button.
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
When clicking my second sound button I get this code:
RangeError: Error #1125: The index 1 is out of range 1.
For me it looks like the new bgmList is excact the same, but something with format, String, vector, I dont really know. I trace them both to be the same. Hope this clears it out. All the other code works like it should with the bgmList that I write directly inside Actionscript. Thank you.
Copy link to clipboard
Copied
var bgmList:Vector.<String> = new <String>
[
something
];
trace(bgmList.length);
var bgmList:Vector.<String> = new <String>
[
"http://lyd.nrk.no/nrk_radio_p1_ostlandssendingen_mp3_h", //sound0 NRK P1
"http://stream.p4.no/p4_mp3_mq",//sound1 P4
];
trace(bgmList.length);
I am now almost 100% sure, I trace the length of the new and old bgmList. the old one traces 3 elements, while the first one only traces 1 element.
What causes this error?
Copy link to clipboard
Copied
var bgmList=new Vector.<String>();
for each (var data:Object in parsedJSONData.streams){//(i=0;i<parsedJSONData.streams.length;i++){
bgmList.push(data);
}
This soled my problems.
Thank you for helping kglad!
Have a nice sunday
Find more inspiration, events, and resources on the new Adobe Community
Explore Now