dynamically created textfields problem

FLASH

    Next

  • 1. datefield component and how to change years
    Hi I am using flash to develop an application and I need to make use of the DateField component. I was wondering if there was an easier way to scroll through dates. Currently, I can change the year only by scrolling through the months a number of times. Is there a better version of DateField component available that would directly let me scroll through the years? Please help. Thanks Mahesh
  • 2. SWF protection / obfuscation
    Hi all! Before you shout "you can't!" please hear the question... ;) I'd like some advice on protecting swf files. I am well aware what can and what can't be done, but I find it hard to figure out what some of the obfuscators do. I guess all of them rename the variables, but is that all they do? Do they add spagghetti code? Do they optimize the code for speed? What is their impact on execution speed? And yes, I know the swf files can't be protected from a determined hacker - but they can and should be protected from a program. At least until artificial intelligence evolves a bit more... :D Flash has become a defacto standard for web delivered applications and provides a powerful programming language too... It is almost unthinkable that every kid can not only see the bytecode (which is the same as in every other platform) but also AS as it was written! From my research I figure the market hasn't evolved enough to provide us with powerful obfuscators yet, but it would be nice to know which ones are the best at this time (and what they are capable of). So: which obfuscators would you recommend? What do they do to protect swfs? Any comment is appreciated. Thanks, Anze
  • 3. integrating flash
    I'm a PSU student and am very new to flash, most of my experience is in c++ and now learning ruby. I need to build a web app hosting mini flash applets, a lot like youtube (just no video) that are dynamic using a database. i know no actionscript or flash design. can anyone help point me in the direction of guides or topics I should study. If anyone can answer a few of my questions through email or IM, I would really appreciate. Thanks!

dynamically created textfields problem

Postby blemmo » Thu, 15 Jun 2006 22:22:05 GMT

Hi people,

 I have a strange problem here: I want to create textfields dynamically that 
are just big enough to hold the text to display. The textfields use a font from 
the library. I get the metrics of the text with TextFormat.getTextExtent(), it 
seems to work ok. However, the last letters of the text are missing in the 
textfield after assigning the text, when the text needs more than 1 line. The 
textfield is sized for 2 lines, but the 2nd line is just empty. I applied 
wordWrap, but the text doesn't show at the 2nd line. This seems to be connected 
to the font that is used: I tested about a dozen different types, and only 1 of 
them displays always the full text, with all other fonts, the last 6 or so 
letters are missing. The text property of the textfields holds the complete 
text; where are the last letters?

 So, are there any known issues with textfields created dynamically? Or any 
trick to display all of the text? I'd like to use a monospaced font, but all I 
have tested have this strange problem.

 Attached is the code used for creatiing the textfields.

 :confused;
 blemmo



 var tf:TextFormat = new TextFormat();
 tf.font = "chatfont";
 tf.size = 8;
 tf.color = 0x990000;

 // get text metrics
 var tfobj:Object = tf.getTextExtent(text,150);

 // create textfield
 
this.mainMC["chatMC"+name].createTextField("tf",0,0,0,150,tfobj.textFieldHeight-
tfobj.descent);
 this.mainMC["chatMC"+name].tf.embedFonts = true;
 this.mainMC["chatMC"+name].tf.selectable = false;
 //this.mainMC["chatMC"+name].tf.multiline = true;
 this.mainMC["chatMC"+name].tf.background = true;
 this.mainMC["chatMC"+name].tf.backgroundColor = 0xCCCCCC;
 this.mainMC["chatMC"+name].tf.border = true;
 this.mainMC["chatMC"+name].tf.borderColor = 0x990000;
 this.mainMC["chatMC"+name].tf.wordWrap = true;
 this.mainMC["chatMC"+name].tf.antiAliasType = "advanced";
 this.mainMC["chatMC"+name].tf.gridFitType = "pixel";
 this.mainMC["chatMC"+name].tf.sharpness = 400;
 this.mainMC["chatMC"+name].tf.text = text;
 this.mainMC["chatMC"+name].tf.setTextFormat(tf);


Re: dynamically created textfields problem

Postby the fleece » Thu, 15 Jun 2006 22:54:18 GMT

what happens if you dont use the calculated height (from getTextExtent) or 
maybe cheating it higher by a few pixels?

 and what about autoSizing?, if you set the textfield height to 1, and the 
width to 150, with muliline and text wrapping on, it should size it exactly for 
you.

 From my experiences getTextExtent isn't always accurate and different fonts 
behave differently


Re: dynamically created textfields problem

Postby blemmo » Fri, 16 Jun 2006 00:24:12 GMT

Good hint checking the height... I misunderstood the meaning of 'descent', so 
the textfield was simply too small because the height was set to 
tfobj.textFieldHeight - tfobj.descent. So the last line didn't have the space 
to display the content... d'oh. Set the height back to tfobj.textFieldHeight, 
now it's fine. =)

 greets,
 blemmo


Re: dynamically created textfields problem

Postby the fleece » Fri, 16 Jun 2006 00:31:29 GMT

great - but is there a reason not to use
autoSize=true

Re: dynamically created textfields problem

Postby blemmo » Fri, 16 Jun 2006 00:40:14 GMT

Yep, the reason is I never tried that. :)

 No... I'm just about to give it a try, but I want to draw a fancy border 
around the textfield (other than the border that comes with the textfield), so 
I guess I'll need the metrics info anyway. Another thing is that I want the 
width to be not more than 150, gotta check if that's possible with auto-size. 
Have to try that now... thx for the input!

 blemmo


Re: dynamically created textfields problem

Postby the fleece » Fri, 16 Jun 2006 01:06:30 GMT

if you have multiline and wordwrap on, autoSize will keep the width,
if wordWrap and multiline are off it will size the width

Re: dynamically created textfields problem

Postby blemmo » Fri, 16 Jun 2006 03:07:07 GMT

The autoSize property is quite handy, thx for the info. Attached is what I have 
now, works fine. The size fits the text when width < 150, else it wraps at 150. 
No missing letters =)

 cheers,
 blemmo



 var tf:TextFormat = new TextFormat();
 tf.font = "chatfont";
 tf.size = 8;
 tf.color = 0x990000;
 var tfobj:Object = tf.getTextExtent(text);

 this.mainMC["chatMC"+name].createTextField("tf",0,0,0,150,12);
 if (tfobj.textFieldWidth > 150){					
 	this.mainMC["chatMC"+name].tf.wordWrap = true;
 }
 this.mainMC["chatMC"+name].tf.embedFonts = true;
 this.mainMC["chatMC"+name].tf.selectable = false;
 this.mainMC["chatMC"+name].tf.html = true;
 this.mainMC["chatMC"+name].tf.autoSize = "left";
 this.mainMC["chatMC"+name].tf.antiAliasType = "advanced";
 this.mainMC["chatMC"+name].tf.gridFitType = "pixel";
 this.mainMC["chatMC"+name].tf.sharpness = 400;
 this.mainMC["chatMC"+name].tf.htmlText = text;
 this.mainMC["chatMC"+name].tf.setTextFormat(tf);


Similar Threads:

1.Set TextField.selecable = false For all dynamically created textField

I have created more than 100 textfields throughout my project.   And it'll be 
very time comsuming to go through all my AS files and located all the 
textfields and set this property (selectable = false).  

 Any idea on how I could do this faster or easier? 

2.Create and dynamically load into textField problem!

I seem to have the exact same problem along with other problems with created dynamic text fields.  I been working with flash for years and I never seen flash code act so wierd.  I am building an App and it really seems that createTextField is buggy and unreliable.

mytext.embedFonts = false;     text shows up fine
mytext.embedFonts = true;      text dissapears yet sometimes works, how i have yet to figure that out.

From what I can tell, its a run-time error in flash.  As like you said, you have to space the code through a couple frames.  This makes it a nightmare for parent actionscript calls or functions.




3.Alpha when creating textfields dynamically?

Hi

I want to create my textboxes on my stage dynamically and give them a sort
of alpha tint. However, the following line doesn't seem to work (although it
comes straight from the library). Is there anyone who could give me some
more info about setting the alpha property of your textfield?

Message_txt._alpha = 20;

Thanks



4.Dynamically attaching scrollbars to actionscript created textfields located inside movieclips

Here's the problem...Im creating a textfield with AS and loading in the content 
from a txt file...I want to attach scrollbars to the textfield when 
neccessary... Below is a copy of the script im using to create the txt field.  
This script is located inside a movieclip....Any help you can offer would be 
appreciated. I can be reached best through email at  XXXX@XXXXX.COM 

 here's the script

 //create a blank text box and set its parameters
 createTextField("theTypeBox",100,0,0,498,200);
 theTextBox.background=true;
 //theTextBox.border=true;
 //theTextBox.backgroundColor=0xFFFFFF;//white
 //theTextBox.borderColor=0x000000;//black
 theTypeBox.multiline=true;
 theTypeBox.wordWrap=true;
 theTypeBox.variable="myAbout";
 //create some formatting for our text box
 myTextFormat = new TextFormat();
 myTextFormat.font = "Arial";
 myTextFormat.size = 12;
 myTextFormat.color=0xFFFFFF;//white
 //format our text box
 theTypeBox.setNewTextFormat(myTextFormat);
 // load our text
 loadVariables("aboutbloc_001.txt", this);

 stop();

5.Dynamically create textfield in a Movieclip subcl

I am trying to programmatically create a textfield in a movieclip subclass. It 
will not let me compile the following:

 class Bouncer extends MovieClip {
   //constructor
   public function Bouncer() {
     	this.createTextField("text_txt", this.getNextHighestDepth(), 0, 0, 60, 
20);
                      text_txt.text = "hello world";    ***** This line gives a 
compiler error. property text_txt does not exist??? *****
     	}
 }

 Would someone know how to put a textfield in a subclassed movieclip and be 
able to change the text programmatically? 

 Thanks in advance.

 Nicholas Crosby

 BTW: I did try it the other way .... adding a textfield to the movieclip on 
the timeline. I could not access the text_txt.text property at in the Bouncer 
class (where I subclassed the movieclip) at run-time though. If anyone knows 
how to do it this way, that would be perfect too.

6. Netscape problems whith dynamically loading ASP into a textfield

7. problem with TextFields created dynamicly

8. Problems with addListener to a danamic created textfield



Return to FLASH

 

Who is online

Users browsing this forum: No registered users and 81 guest