I’m having trouble pulling CSV data from a Google Sheet into my AS3 project. It works fine in the Flash CS5 IDE and when I open the link in a browser. But when I run it in a web browser (local or online), it just gets stuck without loading or showing any errors.
Here’s the code I’m using:
var dataRequest:URLRequest = new URLRequest(sheetURL);
var dataLoader:URLLoader = new URLLoader();
dataLoader.addEventListener(Event.COMPLETE, handleDataLoaded);
dataLoader.addEventListener(IOErrorEvent.IO_ERROR, handleDataError);
dataLoader.load(dataRequest);
The sheet is published and accessible. Any ideas why it’s not working in the browser? Could it be a security setting or something else I’m missing?
I’ve run into similar issues before when working with external data in AS3. One thing that helped me was using the Security.loadPolicyFile() method before making the request. It tells Flash to load a policy file from the specified domain, which can resolve some security restrictions.
Try adding this line before your URLRequest:
Security.loadPolicyFile(“https://docs.google.com/crossdomain.xml”);
Also, make sure you’re using the correct URL format for Google Sheets CSV export. It should look something like:
https://docs.google.com/spreadsheets/d/[YOUR_SHEET_ID]/export?format=csv
If that doesn’t work, you might need to look into using a server-side proxy to fetch the data and pass it to your Flash application. This bypasses cross-domain issues entirely.
Let me know if any of these suggestions help!
I encountered a similar problem when working with Google Sheets data in AS3. Have you considered using the URLVariables class? It can help with encoding the request properly. Here’s a snippet that worked for me:
var vars:URLVariables = new URLVariables();
vars.key = ‘your_api_key’;
vars.sheet_id = ‘your_sheet_id’;
var request:URLRequest = new URLRequest(‘https://sheets.googleapis.com/v4/spreadsheets/’ + vars.sheet_id + ‘/values/Sheet1’);
request.data = vars;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onDataLoaded);
loader.load(request);
Also, ensure you’re using HTTPS for the request. Some browsers block mixed content, which could cause issues if your site is on HTTPS but the request is HTTP. If you’re still stuck, try logging the error events to get more details on what’s going wrong.
hey there Nova56, sounds like a tricky issue! have u checked if it’s a cross-domain security problem? browsers can be picky bout that. try setting up a crossdomain.xml file on ur server or use a proxy script to fetch the data. also double check the url is correct and the sheet perms are set to public. good luck!