Skip to main content
Participating Frequently
June 3, 2014
Answered

published flash banner don't show imported JSON information

  • June 3, 2014
  • 1 reply
  • 775 views

I have a .swf banner that in adobe FlashCS6 plays fine, but when I export it ( .swf and .html),
the banner looses JSON information taken from online JSON file.

I upload the .swf banner to localhost so it should do the trick, but it doesn't.

What am I doing wrong? I'm loosing my mind! please help!

I upload banner to localhost, so it should



play
();
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

var _jsonPath:String = "http://api.topsport.lt/mobile/?json={%22method%22:%22offers%22,%22id%22:%22all/1/0/4564%22,%22lang%22:%22lt%22,%22os%22:%22a1%22}";
function init(e:Event = null😞void
{
  removeEventListener
(Event.ADDED_TO_STAGE, init);

  
var loader:URLLoader = new URLLoader();
  
var request:URLRequest = new URLRequest();
  request
.url = _jsonPath;
  loader
.addEventListener(Event.COMPLETE, onLoaderComplete);
  loader
.load(request);
}  
init
(); 
function onLoaderComplete(e:Event😞void
{
  
var loader:URLLoader = URLLoader(e.target);
  
var jsonObject:Object = JSON.parse(loader.data);
  
//JsonMan.decode(s:String):Object
  trace
("loader.data: " + loader.data);
  trace
(jsonObject[3].object.bets[0].title);
  
if(i<10){
  country1
.text = String(jsonObject[i].object.bets[0].title).toUpperCase();
  country2
.text = String(jsonObject[i].object.bets[2].title).toUpperCase();
  country1_odds
.htmlText = String("<b>"+ jsonObject[i].object.bets[0].odds + "</b>");
  country2_odds
.htmlText = String("<b>"+jsonObject[i].object.bets[2].odds + "</b>");
  x_odds
.htmlText = String("<b>"+jsonObject[i].object.bets[1].odds + "</b>");
  
var today = new Date();
  
var dd = today.getDate();
  
var mm = today.getMonth()+1; //January is 0!
  
var yyyy = today.getFullYear();

  
if(dd<10) {
  dd
='0'+dd
  
}
  
if(mm<10) {
  mm
='0'+mm
  
}

  today
= mm+'-'+dd+'-'+yyyy;
  trace
(today);

  obj_date
.htmlText = String("<b>" + jsonObject[i].object.date + "</b>");
  i
++;
  
if(i==9){
  i
=0;
  
}
  
}
}

This topic has been closed for replies.
Correct answer dmennenoh

I've added securityErrorEvent and I don't receive the crossdomain error anymore, thanx .

(the host of that link holder has put the crossdomain.xml file in his domain).

But swf still doesn't show the information of the JSON online database.

What else could have caused this problem?


Used Fiddler, or Charles, to help figure out the problem. Using one of those you can see the network traffic and see what is or what's not loading.

1 reply

Inspiring
June 3, 2014

Did you look in your browsers console for any error? Also, with JSON I typically need to add an accepts header to the request for it to work properly. Something like so:

var hdr:URLRequestHeader = new URLRequestHeader("Accept", "application/json");

request.requestHeaders.push(hdr);

pauliusptAuthor
Participating Frequently
June 4, 2014
var acceptHeader:URLRequestHeader = new URLRequestHeader("Accept", "application/json");
request.requestHeaders.push(acceptHeader);

I've added this code to the init() funtion
also added

import flash.events.*;

import flash.net.URLRequestHeader;

import flash.net.URLRequestMethod;

import flash.net.URLVariables;


In console I get:

Failed to load resource: net::ERR_NAME_NOT_RESOLVED https://cloudssl.my.phpcloud.com/super/contentScript.js

2Failed to load resource: the server responded with a status of 404 (Not Found) http://api.topsport.lt/crossdomain.xml

GET http://api.topsport.lt/crossdomain.xml 404 (Not Found) crossdomain.xml:1

How can I fix it?

Inspiring
June 4, 2014

I don't know what contentScript.js is, but I thought crossdomain.xml might be a problem... You're trying to load data from outside the domain your swf is on - so the other domain needs to have a crossdomain.xml file that says it allows you to read from that domain. You can Google for all kinds of info.