A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3, Pass a external variable to a function

Threaded View

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    6

    AS3, Pass a external variable to a function

    Hi,

    I have an external log file which name changes each session, with the format XXXXX.log

    I need to load it inside a swf to show its data, but each time the log´s name is different, I need to open the .fla, changing the name of the file and then republishing the swf.

    So I have made a simple script to load another .txt, to type manually in it the 5 number of the log´s name and load it externally inside the swf:

    Code:
    var logNumLoader:URLLoader = new URLLoader();
    logNumLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
    logNumLoader.addEventListener(Event.COMPLETE, loadedLogNum);
    logNumLoader.load(new URLRequest("infoLogNum.txt"));
    
    function loadedLogNum(e:Event):void {
    
             trace(e.target.data.logNum);
    
            }
    The "infoLogNum.txt" contains just a variable, which is the manually typed name of the .log, like:

    Code:
    logNum=12345
    This script works perfect, as it outputs the variable value, in this case "12345".


    But I need this "logNum" value to be passed inside another function that loads and opens the XXXXX.log (see in the code at the bottom):

    Code:
    ...
    
    var tracksLoader:URLLoader = new URLLoader();
    tracksLoader.addEventListener(Event.COMPLETE,onTracksLoaded);
    tracksLoader.addEventListener(IOErrorEvent.IO_ERROR,onTracksError);
    tracksLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onTracksError);
    
    loadTracks();
    
    function onTracksLoaded(e:Event):void {
        trace("onTracksLoaded");
        parseTracks(tracksLoader.data); 
        reload.start(); 
    }
    
    function onTimer(event:TimerEvent):void{ 
        loadTracks();
    }
    
    function onTracksError(e:Event):void {
        trace("onTracksError", e);
        reload.start();
    }
    
    function loadTracks():void {
        tracksLoader.load(new URLRequest(logNum+".log")); 
    }

    While I cannot assign the value of logNum to the last function, the .log cannot be opened.

    I have no clue on how to make it work. Any ideas, please?

    TIA
    Last edited by pibo; 08-06-2010 at 06:14 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center