Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

loadVars( ) and line breaks, trouble

I thought I had compensated for all the weird ways to do line breaks for Macs and PCs...  But apparently NOT !

The code below works fine in the Flash 8 Pro IDE, also works fine when run in Safari, Firefox and IE on a Mac (as LOCAL FILES), but does NOT work when uploaded and run in Safari, Firefox or IE from the internet....

The code below reports that only ONE line has been read into the array
from the file at ---
   http://www.armchair-travel.com/vt/105_Hospitality/descr.txt

 I know there are 53 lines in the file....

What am I doing wrong, please ?

===============================


var loadFile = new LoadVars();
loadFile.onData = function(theDescr:String) {  // called when data file is Completely Loaded
      var theLines:Array;
      // Split either Mac or PC formatted descr.txt files into separate lines
      theDescr = String(theDescr).split("\r\n").join("\r");
      //
      theDescr = theDescr.split("\t").join("");    // remove tabs
      theLines = String(theDescr).split("\r");  // break into lines
      //
      statusField.text = "descr.txt: " + theLines.length + " lines loaded."
.....
...
..

}


0
Donelson
Asked:
Donelson
  • 5
  • 4
1 Solution
 
Aneesh ChopraCommented:
Issue is in the following line
----------
 theLines = String(theDescr).split("\r");  // break into lines
--------------

you should use "\n" here..
-----------
 theLines = String(theDescr).split("\n");  // break into lines
----------

Rgds
Aneesh
0
 
Aneesh ChopraCommented:
Problem is :

following line of code not working actually.
(you can remove this line of code... it is doing nothing.)
----------
 theDescr = String(theDescr).split("\r\n").join("\r");
----------

flash does not get "\r\n" to split... that so it has nothing to join using "\r"...


0
 
DonelsonAuthor Commented:
When I use your suggestions, then the program does not work on local machines.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Aneesh ChopraCommented:
Use the following code it will work for both
----------
var loadFile = new LoadVars();
loadFile.onData = function(theDescr:String) {  // called when data file is Completely Loaded
     var theLines:Array;
     // Split either Mac or PC formatted descr.txt files into separate lines
     theDescr = String(theDescr).split("\r\n").join("\n");
     //
     theDescr = theDescr.split("\t").join("");    // remove tabs
     theLines = String(theDescr).split("\n");  // break into lines
     //
     statusField.text = "descr.txt: " + theLines.length + " lines loaded."
.....
...
..

}
-------------

here if text has "\r\n" replace it with "\n" and later we are spliting the lines with" \n"

Rgds
Aneesh

0
 
DonelsonAuthor Commented:
When I load the file Locally on the Mac, the line break is charCode 0x0d (13).

When I load the file via the internet (on the Mac), the line break char code is 0x0a (10).

What kind of BULLSHT is that !???  

What kind of brain damage switches chars around in a file differently between Local Access and Internet Access ?

0
 
DonelsonAuthor Commented:

-- "here if text has "\r\n" replace it with "\n" and later we are spliting the lines with" \n"

Does not work on Mac. Mac uses only 0x0d.
0
 
Aneesh ChopraCommented:
It may depend on server, how server parse a normal text file..
anyway just look for solution to your problem,

My above suggestion will work fine for both...

Rgds
Aneesh
0
 
Aneesh ChopraCommented:
ok then here the solution
----------
var loadFile = new LoadVars();
loadFile.onData = function(theDescr:String) {  // called when data file is Completely Loaded
     var theLines:Array;
     // Split either Mac or PC formatted descr.txt files into separate lines
     theDescr = String(theDescr).split("\r\n").join("\r");
     theDescr = String(theDescr).split("\n").join("\r");
     //
     theDescr = theDescr.split("\t").join("");    // remove tabs
     theLines = String(theDescr).split("\r");  // break into lines
     //
     statusField.text = "descr.txt: " + theLines.length + " lines loaded."
.....
...
..

}
--------------

replace "\r\n" with "\r",
then replace existing "\n" with also "\r"

and split the lines now using "\r"

Rgds
Aneesh
0
 
DonelsonAuthor Commented:
This works now ---
==============


            // Split either Mac or PC formatted descr.txt files into separate lines
            theDescr = theDescr.split("\r\n").join("\n");
            theDescr = theDescr.split("\r").join("\n");
            //
            theDescr = theDescr.split("\t").join("");    // remove tabs
            theLines = theDescr.split("\n");  // break into lines
            //
==============

What a load of horse droppings !!!

Thanks, for your help, Aneesh.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now