Groups | Blog | Home
all groups > flash actionscript > october 2007 >

flash actionscript : createTextField function question



jlucchesi
10/25/2007 9:49:17 PM
Hi - I think what I'm trying to do is fundamental but I'm not doing it
correctly.
I have a swf that has a few different textFields appearing when buttons are
clicked. I thought I could write one function that would handle the creation
of all the textFields so that I could just put a few parameters into the
function call at the onRelease.

So is there a way to make this code into a function (like "makeTF") such that
I could replace "block_txt" with any string I want and call the function like :
makeTF(AnyString, depth, 110,90, 200,60);
??

I appreciate any help with this.
jl

// this works on its own but how do I make a functio

this.createTextField("block_txt",this.getNextHighestDepth,x,y,width,height);

block_txt._x=100;
block_txt._y=60;
block_txt._width=200;
block_txt._height=60;
//block_txt.autoSize = "left";
block_txt.border = true;
block_txt.wordWrap = true;
block_txt.html = true;
block_txt.multiline = true;
block_txt.html = true;
block_txt.condenseWhite = true;
block_txt.styleSheet = my_css;

//t hen I would add text when I call the different TFs
// block_txt.htmlText = "<h5>Whoa Baby</h5>";
kglad
10/25/2007 10:41:21 PM
:



function makeTF(tfs:String, s:String, dep:Number, x:Number, y:Number,
w:Number, h:Number){
this.createTextField(s,dep,x,y,w,h);
with (this[s]){
border = true;
wordWrap = true;
html = true;
multiline = true;
html = true;
condenseWhite = true;
styleSheet = my_css;
htmlText=tfs
}
}
brycebarrand
10/25/2007 10:47:33 PM
Try this:


var tf = makeTF("hey world", "1_tf", 0, 0, 100, 20);

function makeTF(newText:String, id:String, x:Number, y:Number, width:Number,
height:Number):TextField{
var newTf =
this.createTextField(id,this.getNextHighestDepth,x,y,width,height);
newTf.text = newText;
return newTf;
}
jlucchesi
10/26/2007 6:58:55 PM
brycebarrand -

Thanks.

I'm not sure how to call this.
When I put your code on fr1 and then called it on fr10 using different text in
the quotes - all I got was your "hey world" from fr1 and not my text. I'll be
calling this numerous times with different text.

How can I make this work as you intended?

TIA your help.
jl

makeTF("Got World?", "1_tf", 0, 0, 100, 20);
jlucchesi
10/26/2007 7:04:02 PM
Hi kglad,
Thanks for the response. This isn't sinking in. I put your code on fr1 and
called it on frame 10 with the code below. All I got on the screen was a thin
horizontal line about 40px long.

Did you intend for me to add anything to your code? What am I missing?

Thanks again,
JL

makeTF("Here is the text I want", 99,200,140,220,50);
kglad
10/26/2007 7:11:48 PM
jlucchesi
10/26/2007 8:36:09 PM
Kglad -

Got it!

Thanks.
jl

as in......

jlucchesi
10/26/2007 9:00:10 PM
However...
I'm not getting any html results.
If I put "<h1>some text</h1>" I'm not getting any thing different than if I left the <h1> out.
Can this be fixed?
Thanks again.
kglad
10/26/2007 9:32:21 PM
jlucchesi
10/27/2007 4:31:36 PM
kglad - I'm always trying to understand more about coding so I hope you don't
mind a question or two. I understand "s:String" on line 1 and how "s" is used
in line 2 but I don't know "with (this[s])" means. What's going on here?

Also - a weird thing - when I put your code into the actionscript window the
syntax coloring went off such that some of the statements under "with
(this[s])" are all blue and some are not. Is there something I can learn from
that?

Thanks for your instruction.
JL



function makeTF(tfs:String, s:String, dep:Number, x:Number, y:Number,
w:Number, h:Number){
this.createTextField(s,dep,x,y,w,h);
with (this[s]){
border = true;
wordWrap = true; //all blue
html = true; // all blue
multiline = true;
html = true; // repeated intentionally? all blue too
condenseWhite = true;
styleSheet = my_css;
htmlText=tfs // the only one that's all black
}
}
kglad
10/27/2007 5:31:13 PM
array notation is used by flash to convert strings to objects. so, while s is
a string this[s] is an object (the textfield with instance name s).

and the only thing i infer from some properties being highlighted in blue and
others not, is that the flash compiler is less than flawless.
jlucchesi
10/31/2007 12:00:00 AM
kglad -
I think I get it - that anything in square brackets is an array. (its the
simple things that mean so much).

As far as the flash compiler - you're being modest. You just brought it
beyond the limits of its function...nice work!

Thanks for all the coaching.

jl
kglad
10/31/2007 12:00:00 AM
AddThis Social Bookmark Button