A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: If() on a text file?

  1. #1
    Senior Member
    Join Date
    Sep 2008
    Posts
    100

    If() on a text file?

    Hmm... I'm trying to load from a text file that has this as one of its values.

    theDraw=filled?"drawLines":"drawFilled"

    I'm a little unsure as to if this will work at all or if I am trying to do it in the wrong way.

    Here's my code

    Code:
    var source:String="TextFile.txt";
    var filled:Boolean = false;
    var dataFormat:String=URLLoaderDataFormat.VARIABLES;
    
    var loader:URLLoader = new URLLoader();
    loader.dataFormat=dataFormat;
    configureListeners(loader);
    var request:URLRequest=new URLRequest(source);
    try {
    	loader.load(request);
    } catch (error:Error) {
    	trace("Error loading requested document: " + source);
    }
    function configureListeners(dispatcher:URLLoader):void {
    	dispatcher.addEventListener(Event.COMPLETE, completeHandler);
    }
    
    function completeHandler(event:Event):void {
    	var loader:URLLoader=URLLoader(event.target);
    	switch (loader.dataFormat) {
    		case URLLoaderDataFormat.VARIABLES :
    			trace(loader.data.theDraw);
    			break;
    	}
    }
    Any feedback would be nice...

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Do you mean that
    Code:
    theDraw=filled?"drawLines":"drawFilled"
    comes from a text file?
    That doesn't make sense...

    If you wanted to load that as text, it would have to be url encoded, I guess.

    But, and this is the problem, you want be able to evaluate that expression at runtime. When loaded, that's just a string.

  3. #3
    Senior Member
    Join Date
    Sep 2008
    Posts
    100
    Quote Originally Posted by nunomira View Post
    hi,

    Do you mean that
    Code:
    theDraw=filled?"drawLines":"drawFilled"
    comes from a text file?
    That doesn't make sense...

    If you wanted to load that as text, it would have to be url encoded, I guess.

    But, and this is the problem, you want be able to evaluate that expression at runtime. When loaded, that's just a string.
    Do you know what doing that does if you do it within the code?

    Its basically an if() that you declare while making a variable like that. I'm wondering if you can load the variable in the text file and it processes the if() that's within it when it is complete.

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    If you load that, you'll get the following string: filled?"drawLines":"drawFilled"

    Which is exactly the same as defining a variable like this:
    PHP Code:
    var myVar:String 'theDraw=filled?"drawLines":"drawFilled"'
    myVar is a String, you can't evaluate it, i.e., you can't "convert" it to ActionScript.

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    simply pass the variable in your .txt file - &theDraw=filled&

    and use if/else in Flash -

    PHP Code:
    if(loader.data.theDraw == "filled") {
    // do this
    }else{
    // do that
    }

    // or -
    loader.data.theDraw == "filled" ? do this : do that

  6. #6
    Senior Member
    Join Date
    Sep 2008
    Posts
    100
    the main idea behind doing this is getting an if statement in the text file. Of course, flash kicks me in the nuts again and says its impossible...

    Why does all my idea's turn out impossible to do in flash =(

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