LoadVars doesn't work in the browser

Why the LoadVars class only works in the debugger?

Page 1 of 1

3 Replies - 2332 Views - Last Post: 03 November 2009 - 06:47 AM

#1 doriandorian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-November 09

LoadVars doesn't work in the browser

Posted 03 November 2009 - 03:47 AM

Hello,

I have a problem when I try to use the loadVars class in an ActionScript 2 (CS3) file. Actually, it works fine in the debugger but it doesn't work at all from a web browser (IE or FF).

This is my AS code :
_root.testURL = "http://REMOTE_SERVER_IP:PORT/FILE.html";
var myLoadVars:LoadVars = new LoadVars();
_root.info.text = "Loading...";
myLoadVars.load(_root.testURL,myLoadVars);
myLoadVars.onload = function(success:Boolean) {
_root.info.text = "File loaded"; _root.sr.text = myLoadVars.sr;
}



I can see "File loaded" in the info text field, but the file is not called (I checked the server log) when the swf file is loaded into an HTML page and displayed by a web browser. Thus, _root.sr.text is set to undefined.

It may be a security issue, but I really can't see how to solve it. Could anyone help me?

Thanks.

Dorian.

Is This A Good Question/Topic? 0
  • +

Replies To: LoadVars doesn't work in the browser

#2 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: LoadVars doesn't work in the browser

Posted 03 November 2009 - 06:10 AM

What is in your file.html? When your loadVars has loaded, myLoadVars.sr is a property loaded from the target page, so for example if you called a php page that looked like this:
<?php
	 echo '&sr=aValue';
?>


myLoadVars.sr would contain the String 'aValue'. If you're trying to display an html page source, you need to do something like this:
_root.sr.text = unescape(this.toString());


With this change I have been able to load in the source of a local page, as well as a page from kirupa.com and a page from news.bbc.co.uk.
Was This Post Helpful? 0
  • +
  • -

#3 doriandorian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-November 09

Re: LoadVars doesn't work in the browser

Posted 03 November 2009 - 06:14 AM

Hello and thanks for your reply,

Obviously, my file.html is a string like var1=toto&var2=foo&var3=hi. I have checked all the basics before posting! The problem is really not the data file.

What matters is the ability of the swf file to retrieve data from a file (local or distant): it works perfectly if the swf file is run from the debugger or from a .exe file (projector), but it doesn't work if it's embedded into a web page!

Any other idea?
Was This Post Helpful? 0
  • +
  • -

#4 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: LoadVars doesn't work in the browser

Posted 03 November 2009 - 06:47 AM

The standard response here is to say that Flash does not permit loading data across domains unless you use a Cross-Domain Policy File. This is a small xml file that resides on the server that you are trying to load from, and tells flash that loading is permitted. This is the sample file from Adobe:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
	 <allow-access-from domain="www.company.com" />
 </cross-domain-policy> 


It is permitted to use a wildcard (*) in place of the permitted domain.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1