Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-18-2003, 06:29 AM   #1
mediaholic
Registered User
 
Join Date: Jan 2003
Location: berlin
Posts: 130
Default global TextField Problem! Guru wonted

as u probably know TextFormat has no global style
like FStyleFormat so i thought i could make one?

1. idea)
i could wrap createTextField() in some fns which then assigns automaticly some TextField-propertys and sets setTextFormat.
THE PROBLEM
with that is that not all of my TextFields are generated via script, some r created by authoring-time.

2. idea)
is to change the prototype."someproperty" of the TextField,
THE PROBLEM
TextField is not created via standard "new" constructor
so something like TextField.prototype.embedFonts=true;
DOES NOT WORK as well.

3. idea)
i could simply traverse all instances on stage and ask if the instanz is TextFeld and then assgin some fns which makes the formating
THE PROBLEM
i dont know how to do that?

couse if i ask
trace(typeof t_txt.__proto__);
it just givs "object" not TextField or so
---------------------------------------------
does anybody knows how to make kind of global TextFormat
for createTextField()-generated as well as for authoring-time generated TextFields?


this is very general problem, so i think i can't be the only one with that problem:
mediaholic is offline   Reply With Quote
Old 07-18-2003, 12:42 PM   #2
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

You could do this a number of ways. One way would just be to make a TextFormat and assign it a global reference:
ActionScript Code:
_global.myTF = new TextFormat(); myTF.color = 0x000000; myTF.font = "arial"; myTF.size = 10;
Then on any text field , you can just use setTextFormat(myTF).

If you want to make that whole process even more generalized, you could write a custom method, something like this:
ActionScript Code:
MovieClip.prototype.newTextField = function(textString) {     this.createTextField("test_txt", 0, 0, 0, 100, 20);     with (this.test_txt) {         selectable = false;         text = textString;         setTextFormat(myTF);     } // end with (this.test_txt) }  // end newTextField() method
Then, any time you needed to create a textfield, you could just do it like this (creating it on the _root):
ActionScript Code:
var textString = "Hello World!"; _root.newTextField(textString);
You could modify it so as to pass various parameters too:
ActionScript Code:
MovieClip.prototype.newTextField = function(textString, fieldName, args) {     // textString: the text string to be displayed in the field     // fieldName: the name of the textftield     // args is an object with the following properties:     /*         format: the reference to a textformat object         x: the x coordinate         y: the y coordinate         width: the width of the field         height: the height of the field         selectable: true or false         html: true or false         border: true or false         borderColor: the hex color         multililine: true or false         wordWrap: true or false         etc... all the textfield properties you need     */     // initialize the properties     if (textString == undefined) textString = "hello world";     if (fieldName == undefined) fieldName = "myText_txt";     if (args == undefined) var args = new Object();     if (args.format == undefined) args.format = myTF;     if (args.x == undefined) args.x = 0;     if (args.y == undefined) args.y = 0;     if (args.width == undefined) args.width = 100;     if (args.height == undefined) args.height = 20;     if (args.selectable == undefined) args.selectable = false;     if (args.html == undefined) args.html = false;     if (args.border == undefined) args.border = false;     if (args.borderColor == undefined) args.borderColor = 0x000000;     if (args.multiline == undefined) args.multiline = false;     if (args.wordWrap == undefined) args.wordWrap = false;     // etc. etc. for all properties you want     // render the textfield     this.createTextField(fieldName, theDepth++, args.x, args.y, args.width, args.height);     with (this[fieldName]) {         selectable = args.selectable;         border = args.border;         borderColor = args.borderColor;         multiline = args.multiline;         wordWrap = args.wordWrap;         if (args.html == true) {             html = true;             htmltext = textString;         } else {             text = textString;         } // end if (args.html == true)         if (args.format != undefined) setTextFormat(args.format);     } // end with (this[fieldName]) } // end newTextField() method
Then you could set up an object with the correct properties and pass it to the textfields you create:
ActionScript Code:
// this is the textformat var myTF = new TextFormat(); myTF.font = "arial"; myTF.size = 10; myTF.color = 0x000000; // this is the object which will be passed as args var textProps = new Object(); textProps.format = myTF; textProps.x = 10; textProps.y = 10; textProps.width = 150; textProps.height = 100; textProps.html = true; textProps.multiline = true; textProps.wordWrap = true; // this is the string that will be passed var myTextString = "This is a long text field that will be rendered in html text, with multiple lines and automatic word wrapping. The text is arial, 10 pt typeface, of black color."; // pass those arguments to the newTextField() method _root.newTextField(myTextString, "test_txt", textProps); // for a different textfield, just modify the properties of textProps: textProps.y = 120; var myTextString2 = "This is another long textfield that will be rendered . . . "; // create another textfield _root.newTextField(myTextString2, "test2_txt", textProps);
Something like that should work.
retrotron is offline   Reply With Quote
Old 07-19-2003, 03:20 PM   #3
mediaholic
Registered User
 
Join Date: Jan 2003
Location: berlin
Posts: 130
Default

huh,
tnx for that retrotron,

it's very nice but still doesnt solve the problem
if i created the textField by authoring-time(i mean if i draw it with text-tool)
mediaholic is offline   Reply With Quote
Old 07-20-2003, 10:07 AM   #4
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

Ah, I must have missed your "authoring time" comment in your first post. Anyways, you'll have to do some code if you want to alter anything at author time . . . i.e. even with globalStyleFormat you have to code that in, and the changes don't take affect until run-time. Similarly with movieclips . . . if you want to alter something, you have to do it either globally (with code), or you have to do it individually for each instance (also with code). I reckon the same goes for all flash objects, including textfields. You'll have to write your own coded style format and then use code to apply it to all textfields you create. You can still do this to textfields created at author-time, but just as with every other object, the changes won't take affect until run-time. Hope that helps, and let me know if you find anything.
retrotron is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:12 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.