Groups | Blog | Home
all groups > flash actionscript > june 2005 >

flash actionscript : Dynamic Textbox Problems


MyFlashMXIN
6/17/2005 8:00:12 PM
For some reason my AS fails to set the textfield background color...

Anyone see what I've done wrong here?



function placeContent(xpos, ypos, wpos:Number):Void {
_root.createEmptyMovieClip("textBox", 1);
_root[textBox].createTextField("mytext", 1, xpos, ypos, wpos, 560);
mytext.autoSize = true;
mytext.type = "dynamic";
mytext.multiline = true;
mytext.selectable = false;
mytext.html = true;
mytext.wordWrap = true;
mytext.backgroundColor = 0xFFFFFF;
mytext.border = true;
myformat = new TextFormat();
myformat.color = 0xff0000;
myformat.bullet = false;
myformat.underline = false;
mytext.setTextFormat(myformat);
mytext.variable = "content";
mandingo
6/18/2005 12:00:00 AM
Gee kglad take it easy on the poor lad... and just an aside... if all other
attributes are set "true" or "false", it may be confusing to see background as
"1" even though we know your mathematical mind only records that as true :)
kglad
6/18/2005 1:11:56 AM
it's amazing that works, at all. does it? do you get a textfield that
displays "content" when that function is called?

if you do, it's only because of a confluence of errors. the most serious
errors are the use of _root[textBox] which may be undefined and should be
_root["textBox"] or _root.textBox.

that error may be balanced by the error referencing your textfield as mytext
when it should be _root.textBox.mytext. but because of your first error,
flash my create that textfield on the timeline that contains your code so you
actually get away with using mytext to reference your textfield. or maybe
flash will balk and not create that textfield, at all.

anyway, to set the backgroundColor of a textfield you have to enable the
background property of the textfield. the following corrects the errors i can
see:

function placeContent(xpos, ypos, wpos:Number):Void {
_root.createEmptyMovieClip("textBox", 1);
_root.textBox.createTextField("mytext", 1, xpos, ypos, wpos, 560);
myformat = new TextFormat();
myformat.color = 0xff0000;
myformat.bullet = false;
myformat.underline = false;
with (_root.textBox.mytext) {
autoSize = true;
type = "dynamic";
multiline = true;
selectable = false;
html = true;
wordWrap = true;
background = 1;
backgroundColor = 0xaaaaaa;
border = true;
htmlText = "content";
setTextFormat(myformat);
}
}
kglad
6/18/2005 6:27:58 AM
i didn't mean to be harsh. i just find it hard to believe that the only
problem is the background color. i would think none of that would work.

i just tested it and it does create a textfield. but none of that code works.
i don't see "content" in the textfield. so, it's very misleading to state
this is a background problem.
mandingo
6/18/2005 7:19:48 AM
I took a look at it... it does kinda work... but you are rirrr rrii right... it
worked from lots of mistakes...

the mytext is being created on the _root timeline so it still exists... the
whole movieClip of "textBox" is being ignored due to the incorrect
referencing... so it throws it out to the _root timeline... this could be why
the rest and the content variable are having trouble too...

cheers,

function placeContent(xpos, ypos, wpos) {
_root.createEmptyMovieClip("textBox", 1);
_root[textBox].createTextField("mytext", 1, xpos, ypos, wpos, 560);
mytext.autoSize = true;
mytext.type = "dynamic";
mytext.multiline = true;
mytext.selectable = false;
mytext.html = true;
mytext.wordWrap = true;
mytext.backgroundColor = 0xFFFFFF;
mytext.border = true;
myformat = new TextFormat();
myformat.color = 0xff0000;
myformat.bullet = false;
myformat.underline = false;
mytext.setTextFormat(myformat);
mytext.setNewTextFormat(myformat);
mytext.variable = "content";
}
this.placeContent(100, 100, 300);
this.content = "try this on for size";
MyFlashMXIN
6/20/2005 12:00:00 AM
kglad,

no need for appologies... I'm glad someone took the time to explain to me the
mistakes I had made.

BTW: My code, all be it way out of proper format, worked other than setting
the background...

mandingo,

The code you posted worked like the code I had posted... no background.... :-P

mandingo
6/20/2005 11:13:18 PM
yes I know... i hadn't added background = true...

but I was re-displaying that by way of replying to kglad's how and why yours
worked at all... I mentioned that it worked because of Flash creating the
events at certain locations and then the reference to the content variable was
out too... then posted code that would display that apparent anomoly... I would
have thought that the location was undefined and the rest of the code would
have errored... and from kglad's response he may have been of the same
opinion...
mandingo
6/21/2005 12:00:00 AM
or ends at the bottom of the well!

kglad
6/21/2005 1:39:21 AM
AddThis Social Bookmark Button