-
AS3 CS3 - Set Color & External Text.
Hi guys, just wondering if someone can point me in the right direction.
I am trying to use AS3 to create a rectangle that is a specific size and color. I have managed to do this, that's not the problem.
The problem is I now want to have a text file with a color number value in it, and make my script read that text file and set the color.
Is this possible? Is there a way I can set a variable or other value depending on what info is in a text file?
This is the code I have at the moment:
Code:
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.load(new URLRequest("backgroundcolor.txt"));
var square:Shape = new Shape();
square.graphics.beginFill(0x000000);
square.graphics.drawRect(0, 0, 160, 280);
var myColor:ColorTransform = square.transform.colorTransform;
myColor.color = myTextLoader;
square.transform.colorTransform = myColor;
addChild(square);
The error I get is:
1067: Implicit coercion of a value of type flash.net:URLLoader to an unrelated type uint.
Im guessing my problem is this line ''myColor.color = myTextLoader;'' it worked when I just set a color instead.
And just in case, here is the code I got to work:
Code:
var square:Shape = new Shape();
square.graphics.beginFill(0x000000);
square.graphics.drawRect(0, 0, 160, 280);
var myColor:ColorTransform = square.transform.colorTransform;
myColor.color = 0x9999FF;
square.transform.colorTransform = myColor;
addChild(square);
thanks for any help.
EDIT:
actually, any help on anything to do with loading external text, wrigting to external text folders and anything like that would be much appreciated.
i spent last night on google looking for tutorials, and have learned a bit, but i would like to know more.
thanks
Last edited by HatsOff; 08-12-2009 at 07:48 PM.
-
lemon juice hurts your eyes
Writing to folders will probably require php to create a file or overwrite a file on your server.
And I'm not good at all with that
Anyway, the error says you're trying to set a variable of type uint to a URLLoader, so to get rid of it, you have to get to the data inside of that loader:
PHP Code:
myColor.color = Number(myTextLoader.data)
So you convert what is inside of the loader into a Number (probably of the format 0xXXXXXX).
One thing you should use though, is an EventListener so you know when the .txt file is loaded.
When it's not loaded yet and you try setting myColor to the data inside of the loader you will get an error.
PHP Code:
myTextLoader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(e:Event):void { myColor.color = Number(e.target.data); // in which e.target refers to myTextLoader // other actions }
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
-
Thanks, and yes, i have now discovered that i do indeed need php to write.
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
|