-
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...
-
Registered User
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.
-
Originally Posted by nunomira
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.
-
Registered User
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.
-
FK'n_dog
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;
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|