0

I'm trying to work out from an old as2 tutorial how to amend a script for as3/php eCard system for a business card but I can't find reference anywhere to how you'd do the following :

AS2 :

loadVariablesNum ("http://www.theSite.com/Cards/bCard/"+BcardText+".txt", 0);

AS3 :

// setup URLLoader
var loader:URLLoader = new URLLoader;
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

// event listener for function when loaded
loader.addEventListener(Event.COMPLETE, varsLoaded);

// file URLRequest
loader.load(new URLRequest("http://www.theSite.com/Cards/bCard/"+BcardText+".txt"));

// set the variables from the data.txt file
function varsLoaded (event:Event):void {
    //Load Data
cName.text = loader.data.cName;
cDescription.text = loader.data.cDescription;
}

With this it kicks out the following error message :

  • Error opening URL 'http://www.theSite.com/Cards/bCard/undefined.txt' Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs. at Error$/throwError() at flash.net::URLVariables/decode() at flash.net::URLVariables() at flash.net::URLLoader/onComplete()

I can't work out where or how you define the +BcardText+ for it to pull it in.

Any help would be gratefully received.

I'm not sure If I'm even close as its from as2, it seems the logical approach for loading it but I've not dealt with external files having parameters before.

Thanks in advance if anyone can help out in anyway!

NEW LOADER - FIXED!!!

var loader:URLLoader = new URLLoader();   
var request:URLRequest = new  URLRequest("http://www.theSite.com/Cards/bCard/"+BcardText+".txt");           
loader.load(request);

loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

function loaderIOErrorHandler(event:IOErrorEvent):void{
trace("ioErrorHandler: " + event);
}

// set the variables from the .txt file
function completeHandler (event:Event):void {

//trace("Content: " + loader.data);

this.Variable1.text = loader.data.Variable1; //Whatever dataField1 you saved as
this.Variable2.text = loader.data.Variable2; //Whatever dataField2 you saved as
}

Then you just setup FlashVars to distinguish the +BcardText variable in the loader prior to committing it!

esadude
  • 37
  • 1
  • 10
  • maybe help this http://stackoverflow.com/questions/3487479/url-encode-variable-in-as3 ? – Eugen Nov 03 '12 at 21:27
  • Thanks @Eugen. I did think to try that as I had a similar problem previously but that just throws up this Error message : Error opening URL 'http://www.theSite.com/Cards/bCard/undefined.txt' Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://www.esadude.com/eCards/dBText/undefined.txt at _eCard_SETUP_fla::MainTimeline/frame20() – esadude Nov 03 '12 at 21:54

2 Answers2

0

BcardText was a variable defined in the as2 project. Look around (maybe on previous frames?) and you should find where it got declared. It looks like an ID to represent the card. So each card has a unique file 12345.txt, 09876.txt etc.

Jason Reeves
  • 1,716
  • 1
  • 10
  • 13
  • Hi @Jason, the only reference to the **+BcardText** I can find is in the php script which stores and outputs the data files once the initial card has been created. I tried setting it as a variable in the file with the link but still no luck and I'm not sure if this is the right way to even go about loading it so searching for an alternative isn't so easy as I'm not even sure what you call a file with variables attached to the end? – esadude Nov 04 '12 at 10:31
  • can you post a link to the tutorial you are using? If I can see what you are working from, I can help you port it to as3. – Jason Reeves Nov 04 '12 at 16:49
  • Here's the link to the tutorial, its quite good but it seems here's little available online in way of AS3 - [link]http://www.flash-db.com/Ecards/EcardsTutorial.php?page=1 I managed to convert it all finally after several days of major stress and will re-write the code and feature it to help others in the next day or so as it's something so many seem to struggle with from what I've seen online. Will be nice to give something back! – esadude Nov 04 '12 at 19:59
0
var loader:URLLoader = new URLLoader();   
var request:URLRequest = new  URLRequest("http://www.theSite.com/Cards/bCard/"+BcardText+".txt");           
loader.load(request);

loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

function loaderIOErrorHandler(event:IOErrorEvent):void{
trace("ioErrorHandler: " + event);
}

// set the variables from the .txt file
function completeHandler (event:Event):void {

//trace("Content: " + loader.data);

this.Variable1.text = loader.data.Variable1; //Whatever dataField1 you saved as
this.Variable2.text = loader.data.Variable2; //Whatever dataField2 you saved as
}

Then you just setup FlashVars to distinguish the +BcardText variable in the loader prior to committing it!

Have scoured the Internet and gone half mad working this out but finally chuffed to say I broke it's back...!

A big thanks for helping point me in the right direction guys. @Jason @Eugen

Θ)

esadude
  • 37
  • 1
  • 10