Loading a text file into a global variable issue - really a global var?

From all the documentation and examples I can find, it appears that it would be
correct to create a global array variable [outside of any functions] to load image names into,
then use these images for a slideshow. I want to make the app dynamic, in that changing the text file gives a new set of images.
The global variable goes null [no values] after the load event listener. Why is that?
Isn't global, well global, and alive for the duration of the SWF?
PARAMS.TXT:
monthNames=January,February,March,April,May,June,July,August,September,October,November,De cember&dayNames=Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
CODE:
var dNames:Array = new Array();
var mNames:Array = new Array();
var request:URLRequest = new URLRequest("images/params.txt");
var variables:URLLoader = new URLLoader();
variables.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.addEventListener(Event.COMPLETE, completeHandler);
try
variables.load(request);
catch (error:Error)
trace("Unable to load URL: " + error);
trace("2 mNames 2: " + mNames[2]);
trace("2 dNames 3: " + dNames[3]);
stop();
function completeHandler(event:Event):void
var loader:URLLoader = URLLoader(event.target);
dNames = loader.data.dayNames.split(",");
mNames = loader.data.monthNames.split(",");
trace(loader.data.dayNames);
trace("1 mNames 2: " + mNames[2]);
trace("1 dNames 3: " + dNames[3]);
OUTPUT:
2 mNames 2: undefined
2 dNames 3: undefined
Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
1 mNames 2: March
1 dNames 3: Wednesday
How do I access these values after loading from the external file, after the load?
Thanks in advance.

The statement you quoted from whatever Adobe documentation is correct.
If you want to load the data into the arrays before anything else happens, then have anything else that happens execute via the completeHandler function... after the data is loaded and processed into the arrays.
the command: loadFile() executes before the trace("2:" +images[4]); command.  The loadFile function is processed and the loading process BEGINS... but starting the loading does not delay the main processing from continuing down the line--the loading itself becomes a secondary/background task.  The command was to execute the loadFile function and the processing of that function was completed.  If you don't believe so, then add a trace...
function loadFile():void
     vars.dataFormat = URLLoaderDataFormat.VARIABLES;
     vars.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
     vars.load(new URLRequest("images/fnames.txt"));
     trace("started loading");
If you add that trace, you should see that the loadFile function execution is completed and the next line in your code is then processed... trace(2....)
The addEventlistener does not stop anything.  The addEventListener code is assigning a monitor, not a traffic controller... it is telling the monitor to indicate when the data has finished loading.  It is not telling anything to stop program execution.
So if you want to wait until the data is loaded before you do anything else... it goes....
function onComplete(evt:Event):void
     var urlVars:URLVariables = evt.target.data;
     images = vars.data.images.split(",");
     tnails = vars.data.thumbnails.split(",");
     ................HERE.................

Similar Messages

  • How can I use sql loader to load a text file into a table

    Hi, I need to load a text file that has records on lines tab delimited into a table. How would I be able to use the sql loader to do this? I am using korn shell to do this. I am very new at this...so any kind of helpful examples or documentation would be very appreciated. I would love to see some examples to help me understand if possible. I need help! Thanks alot!

    You should check out the documentation on SQL*Loader in the online Oracle document titled Utilities. Here's a link to the 9iR2 version of it: http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/server.920/a96652/part2.htm#436160
    Hope this helps.

  • Loading a text file into Terminal App

    Hi,
    I  am  trying  to  load  a  textfile  into  my  Terminal  App  using  the  Import  utility  under  the  Shell  drop  down  menu.
    But  when  I  try  choosing  the  text  files  after  clicking  Import,  I  am   unable  to  select  a  text  file  because  they  are 
    all  greyed  out. Only  folders  seems  to  be  selectable.
    Please  help.

    I have no idea what you are trying to do. What does "load a textfile" mean?
    The Import… command is for importing a Terminal settings file (exported using the Export Settings… command on another computer or user).

  • Loading large text files into java vectors and outof memmory

    Hi there,
    need your help for the following:
    i'm trying to load large ammoubnts of data into a Vector in order to concatenate several text files and treat them, but i'm getting outofmemory error. I even tried using xml structure and saving to database but the error is still the same. Can you help?
    thanks
    here's the code:
    public void Concatenate() {
    try {
    //for(int i=0;i<1;i++) {
    vEntries =  new Vector();
    for(int i=0;i<BopFiles.length;i++) {
    MainPanel.WriteLog("reading file " + BopFiles[i] + "...");
    FileInputStream fis = new FileInputStream(BopFiles);
    BufferedInputStream bis = new BufferedInputStream(fis);
    DataInputStream in = new DataInputStream(bis);
    String line = in.readLine();
    Database db = new Database();
    Connection conn = db.open();
    while(line != null) {
    DivideLine(BopFiles[i], line);
    line = in.readLine();
    FreeMemory(db, conn);
    MainPanel.WriteLog("Num of elements: " + root.getChildNodes().getLength());
    MainPanel.WriteLog("Done!");
    } catch (Exception e) {
    e.printStackTrace();
    public void DivideLine(String file, String line) {
         if (line.toLowerCase().startsWith("00694")) {
              Header hd = new Header();
              hd.headerFile = file;
              hd.headerLine = line;
              vHeaders.add(hd);
         } else if (line.toLowerCase().startsWith("10694")) {
              Line entry = new Line();
              Vector vString = new Vector();
              Vector vType = new Vector();
              Vector vValue = new Vector();
              entry.name = line.substring(45, 150).trim();
              entry.number = line.substring(30, 45).trim();
              entry.nif = line.substring(213, 222).trim();
              entry.index=BopIndex;
              entry.message=line;
              entry.file=file;
              String series = line.substring(252);
              StringTokenizer st = new StringTokenizer(series, "A");
              while (st.hasMoreTokens()) {
                   String token=st.nextToken();
                   if(!token.startsWith(" ")) {
                        vString.add(token);
                        vType.add(token.substring(2,4));
                        vValue.add(token.substring(4));
                   token=null;
              entry.strings= new String[vString.size()];
              vString.copyInto(entry.strings);
              entry.types= new String[vType.size()];
              vType.copyInto(entry.types);
              entry.values= new String[vType.size()];
              vValue.copyInto(entry.values);
              vEntries.add(entry);
              entry=null;
              vString=null;
              vType=null;
              vValue=null;
              st=null;
              series=null;
              line=null;
              file=null;
              MainPanel.SetCount(BopIndex);
              BopIndex ++;
    public void FreeMemory(Database db, Connection conn) {
    try {
    //db.update("CREATE TABLE entries (message VARCHAR(1000))");
                   db.update("DELETE FROM entries;");
                   PreparedStatement ps = null;
                   for( int i=0; i<vEntries.size(); i++ ) {
                        Line entry = (Line) vEntries.get(i);
                        String value = "" + entry.message;
                        if(!value.equals("")) {
                             try {
                                  ps = conn.prepareStatement("INSERT INTO entries (message) VALUES('" + Tools.RemoveSingleQuote(value) + "');");
                                  ps.execute();
                             } catch(Exception e) {
                                  e.printStackTrace();
                                  System.out.println("error in number->" + i);
                   MainPanel.WriteLog("Releasing memory...");
         vEntries = null;
         vEntries = new Vector();
         System.gc();
              } catch (Exception e1) {
                   e1.printStackTrace();

    Well, i need to treat those contents, and calculate values withing those files, so wrinting files using FileInputstream wont do. for instance i need to get line 5 from file 1, split it, grab a value according to its class (value also taken) and compare it with another line of another file, adding those values to asingle file.
    that's why i need vector capabilities, but since these files have more than 5 Mb each, an out of memory error is returned by loading those values into vector.
    A better explanaition:
    Each file has a line like
    CLIENTNUM CLASS VALUE
    so if the client is the same withing 2 files, i need to sum the lines into a single file.
    If class is the same, then sum values, if not add it to the front.
    we could have a final line like
    CLIENTNUM CLASS1 VALUE1 CLASS2 VALUE2

  • How to load external text file into a Form?

    Hi,
    I made a menu with 1-5 in a Form and 5 external text files. I want the user who is able to view the text content of the text file when he chooses one of them from the menu. And the text file screen has a "Back" command button to let him go back.
    How can I do it and can it support other languages such as Chinese and Japanese?
    Thanks for help.
    gogo

    Sorry, I made the mistake about the subject, it should be loading local file, not external file through http.
    I wrote a method but it throwed an exception when the midlet was run.
    private void loadText()
    try {
    InputStream is = this.getClass().getResourceAsStream("/text.txt");
    StringBuffer sb = new StringBuffer();
    int chr;
    while ((chr = is.read()) != -1)
    sb.append((char) chr);
    is.close();
    catch (Exception e)
    System.out.println("Error occurs while reading file");
    I put the text.txt file in the same folder with the main file (extends midlet). How can I load the text content and display it on StringItem?
    Thanks for any help.
    gogo

  • Loading a text file on startup into a hashtable

    I am trying to load to seperate textfiles into the same hashtable.
    The textfiles are something like an employee and employee number everything goes in at the same time. How do i load these text files into the hashtable. Also any good tutorials or code samples on hashtables would be greatly appreciated.
    Thanks In Advance

    You read the text files, one line at a time, and break up each line in whatever way you need to. Then you choose the bits to put in the hashtable (key and value) for each line and put those bits into the hashtable.
    http://java.sun.com/docs/books/tutorial/essential/index.html
    http://java.sun.com/docs/books/tutorial/collections/index.html

  • How to load a text file int JEditorPane and highlight some words (Urgent !)

    I want to load a text file into a JEditorPane and then highlights some keywords such as while,if and else.I am using an EditorKit in order to style the JEditorPane. I have no difficulty while giving the input through the keyboard but lots of exceptions are thrown if i try to load the string from a file.

    Hi,
    I think the setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace) will solve the problem.
    You can create your own Styled Document and set it to the Editor Pane.

  • Loading a text file to a buffer

    Hi,
    I have a very simple question,
    I have a text file which I want to read and load it in a string buffer, but I don't want to user BufferedReader and append line by line,
    is it possible to load the text file into StringBuffer without any loops / appends?
    Thanks,
    S.

    File file = new File("fileName.fileExtension");
    byte[] c = new char[file.length()];
    FileReader reader = new FileReader(file);
    try{
        reader.read(c);
    }catch(IOException e) { System.out.println("An error has ocurred");}
    String makeMeString = new String(c);
    Stringbuffer buff = new StringBuffer(makeMeString);

  • Loading a txt file into an applet.

    as the topic suggests: I want to load a text file into an applet.
    i only got this far:
    public static String load(String path)
                            String date = "";
            File file = new File(path);
            try {
             // Load
            catch (IOException e) {
             e.printStackTrace();
            return date;
           } how do i load the file?
    is it possible to return the data in a list (more convenient)?
    Message was edited by:
    Comp-Freak

    as the topic suggests: I want to load a text file
    into an applet.
    i only got this far:
    public static String load(String path)
    String date = "";
    (path);
            try {
             // Load
            catch (IOException e) {
             e.printStackTrace();
            return date;
           } how do i load the file?
    is it possible to return the data in a list (more
    convenient)?
    Message was edited by:
    Comp-FreakFirst of all, you are going to have to sign your applet if you want access to the local file system (applets run on the client, not the server).
    Second of all ... looking at your code, what is "date?" Is it a String (guessing based on your return value...) here is a simple routine to read a text file, line by line:
    try {
       BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("myfile")));
       String input;
       while( (input = br.readLine() != null ) {
           System.out.println(input);
    }  catch (FileNotFoundException fnfe) { System.err.println("File not found."); }
       catch (IOException ioe) { ioe.printStackTrace(); }

  • How to load a text file (ASCII) into a TS string variable?

    I need to load a ASCII file into a TS string variable for subsequent processing. I tried the SecuenceBuilder DLL (in the examples directory) but it seems that this DLL has a bug. Some text files are not loaded properly. I have also tried the kernel32 functions (openfile, createfile, readfile ... ) handling them as a C program, but with no success. The property loader feature of TS is not the suitable solution for me, because I would have to modify all my text files to include some specific fields (step name, variables, starmarker ...). Doy you know an alternative procedure to load text files or any DLL that implements what I look for ? Any help would be grateful. Cesar ([email protected])

    Hi Cesar,
    I don't know if you have found a solution, but attached is a DLL built in VC that will read the text out of a file into a TestStand variable. The attached sequence file \SequenceFile1.seq contains a step type that is set to call the DLL responsible for reading the file. It reads the file specified under Step.FilePath and stores the data in Step.ReadData. Please let me know if this works for you. I have attached the source as well.
    Regards,
    Bob
    Attachments:
    ReadFile.zip ‏3628 KB

  • Loading data from text file into ListBox

    I have data in a text file that I want to load into a
    listbox... I have fully mastered handling strings and arrays so I'm
    going to need some help...
    I was wondering how do I get flash to load a text file that
    contains the data below.. and display it line for line like I want
    it to list down the component
    "Launch;7.1.7.6"
    "Engine;7.1.7.6"
    "OSX;7.0.0.2" (or something close to that)
    and I was wondering how do i just get it to take it fromt he
    file.. line for line from where it says exeversion in the file and
    list it in the listbox...
    I'm really thankful to anybody that helps.
    Data in text file:
    quote:
    exeversion=Launch;7.1.7.6;
    exeversion=Engine;7.1.7.6;
    exeversion=LinuxX86;7.0.0.2;
    exeversion=LinuxPPC;7.0.0.2;
    exeversion=LinuxMIPS;7.0.0.2;
    exeversion=OSX;7.0.0.2;
    exeversion=Config;7.1.7.6;
    exeversion=UI;7.1.7.7;
    exeversion=JAVA;7.0.4.5;

    nobody cna help me? i really need to know or have a tutorial
    or something so i can learn from it... i really appreciate anyone
    who helps

  • How to read a whole text file into a pl/sql variable?

    Hi, I need to read an entire text file--which actually contains an email message extracted from a content management system-- into a variable in a pl/sql package, so I can insert some information from the database and then send the email. I want to read the whole text file in one shot, not just one line at a time. Shoud I use Utl_File.Get_Raw or is there another more appropriate way to do this?

    how to read a whole text file into a pl/sql variable?
    your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
    ....

  • How can I load a .TXT file into a dynamic text box?

    I am sure that many people know how to load a .txt file into
    a dynamic text box. But I do not. I want to be able to reference a
    txt file from the server into the text box. So that when I change
    the text file it changes in the flash movie without even editing
    the flash file itself. Thank you.

    http://www.oman3d.com/tutorials/flash/loading_external_text_bc/
    I think this is the simplest way to go :)

  • SQL Loader-How to insert -ve & date values from flat text file into coloumn

    Question: How to insert -ve & date values from flat text file into coloumns in a table.
    Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
    How to load such values in columns of database using SQL Loader?
    Please guide.

    Question: How to insert -ve & date values from flat text file into coloumns in a table.
    Explanation: In the text file, the negative values are like -10201.30 or 15317.10- and the date values are as DDMMYYYY (like 10052001 for 10th May, 2002).
    How to load such values in columns of database using SQL Loader?
    Please guide. Try something like
    someDate    DATE 'DDMMYYYY'
    someNumber1      "TO_NUMBER ('s99999999.00')"
    someNumber2      "TO_NUMBER ('99999999.00s')"Good luck,
    Eric Kamradt

  • SQL Loader - Loading Text File into Oracle Table that has carriage returns

    Hi All,
    I have a text file that I need to load into a table in Oracle using SQL Loader. I'm used to loading csv or comma delimited files into Oracle so I'm not sure what the syntax is when it comes to loading a text file that essentially has one value per row and each row is separated by a carriage return. So when you open the text file, the records look like this:
    999999999 <CRLF>
    888888889 <CRLF>
    456777777 <CRLF>
    456555535 <CRLF>
    345688888 <CRLF>
    So each row is separated by a hard return and I need to tell sql loader that the hard return or next row is the next value to insert into the table. Below is an example of a control file I tend to use as a template for loading csv files but I need to modify it to accomodate this new structure.
    OPTIONS (DIRECT=TRUE,ROWS=100000)
    UNRECOVERABLE
    LOAD DATA
    INFILE 'C:\input.txt'
    BADFILE 'C:\input.bad'
    APPEND
    INTO TABLE TEST_TABLE
    FIELDS TERMINATED BY ","
    TRAILING NULLCOLS
    COLUMN_1
    How to I modify the control file above to use hard returns as the field/row delimiter for my text file?
    Thanks

    Hi there,
    Obviously my intention wasn't to post the same message 4 times....I pressed the "Submit Message" button but the submission hung and I pressed it a few times and finally it worked but it created several versions of my post. You need to allow users the ability to delete there own postings...I was looking for this option but didn't have it.
    Sorry

Maybe you are looking for

  • Repeated failure when time machine files moved to bigger drive...

    We are trying to copy our Time Machine archive to a bigger drive. We have done this before a couple of years ago using CarbonCopyCloner and had no serious problems. Tried it this time and it was not successful*. We have tried this again by following

  • Transferring catalogues from Photoshop Elements 5 to Photoshop Elements 9

    The process should be an easy one -- BUT, my new copy of Elements 9 does not list under the FILE column, anything that looks like or works like "Catalogue". Instead of the listing as per the Adobe tutorial as follows: FILE (then) Get Photos & Videos,

  • ALV With Page No.

    Please give the Code(If Possible with Example) which is useful to disply the page no in ALV Report. Thanks Prashanth.

  • Trail Download

    I am downloading a trial version of CS6 Master Collection... when it gets to the extracting step it just freezes up... its been frozen for about 4 hours this morning. is there anyway to completely cancel the download and start over from scratch?

  • And condition within the same table

    Hello all, Was wondering if anyone knows what's the best and most efficient way to query for something similar to the example below. Table1 ID CID VALUE 1 1 a 2 2 b 3 3 c 4 1 c Find me all customer id where value is a and c This should only bring bac