dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3, Pass a external variable to a function

  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.

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Just create a new function.

    function loadedLogNum(e:Event):void {

    openLog(e.target.data.logNum);

    }

    function openLog(_logNum:String)
    {
    var logNum:String = _logNum;
    .......

    }
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    6
    Thank you cancerinform,

    I have changed inside the first function:

    Code:
    trace(e.target.data.logNum);
    with

    Code:
    openLog(e.target.data.logNum);
    And then the second function (without ".......") but it doesn´t work.

    Sorry, but I don´t know how to implement your second function and what´s supposed to be instead of "......."


    (Edit) I have been working on the code with another solution:

    Code:
    var _logNum:String;
    
    function loadedLogNum(e:Event):void {
       trace(e.target.data.logNum);
       _logNum = e.target.data.logNum;
       loadTracks();
    }
    Last edited by pibo; 08-06-2010 at 07:54 PM. Reason: Issue solved.

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