Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
crunchie

Method to determine Max size of textfield?

Recommended Posts

Hi.

 

Unfortunately geometry is not my strong point and I am on a deadline.

 

I am trying to determine if a textfield is larger and / or outside the bounds of the transformManager. If it is larger, I need to scale it and make sure it is always in the confines of the transformManager space. On a side note, i need to scale the size of the text accordingly.

 

Can someone explain the best way to go about this please?

 

Thanks in advance

Link to comment
Share on other sites

AS2 or AS3? Are you familiar with the "bounds" property of TransformManager? You can use it to prevent users from dragging/scaling/moving items outside certain boundaries. And if you want to scale the text too, I'd recommend wrapping the TextField in a Sprite/MovieClip.

Link to comment
Share on other sites

AS2 or AS3? Are you familiar with the "bounds" property of TransformManager? You can use it to prevent users from dragging/scaling/moving items outside certain boundaries. And if you want to scale the text too, I'd recommend wrapping the TextField in a Sprite/MovieClip.

 

Thanks for the quick reply. My situation is a little unique. Maybe if illustrate:-

 

1. Create a transformManager and setBounds.

2. Add a textField, move / scale / rotate it, set text.

3. If the user changes product, remove textField from stage, but keep in memory with x / y / rotation / text properties etc. Destroy current instance of transformManager

4. Create a new transformManager (with different size and setBounds based on new Product.

5. Add the textField back to the transformManager <-- (this is where my issue arises. Often the textField will now be too big and out of the bounds. I want to now determine how much I need to scale it down to fit and (with a bit of luck, scale the text accordingly.

 

I have been looking at the matrix.scale method, and I have had limited luck with it. Alas, i don't fully understand how to use it. So far I have:-

 

var plateRec:Rectangle = _plate.getBounds(this); // TransformManager Bounds
		var tfRec:Rectangle = _tf.getBounds(_plate); // textField bounds
		var matrx:Matrix = new Matrix();
		matrx.scale((plateRec.width / tfRec.width),(plateRec.height / tfRec.height))

		if(matrx.a < 1 && matrx.d < 1)
		{
			_tf.transform.matrix = matrx;
		}

		if(matrx.a < 1 && matrx.d > 1)
		{
			_tf.transform.matrix = new Matrix(matrx.a,0,0,1,0,0);
		}

		if(matrx.a > 1 && matrx.d < 1)
		{
			_tf.transform.matrix = new Matrix(1,0,0,matrx.d,0,0);
		}

 

Thanks for your help so far. [edit] I am using AS3 [/edit]

Link to comment
Share on other sites

I'm rushing against a deadline too, so I don't have time to explain it all, but I'll offer the following thoughts:

 

1) It depends on where your origin is for your scale. If it's in the upper left of the object (the default for TextFields) and the TextField exceeds the boundaries on the left or top sides, it won't matter how much you scale it down - it will never get it back within the boundaries. You'd have to move it too.

 

2) To trigger the bounds sensor and have TransformManager move it back within the bounds (if possible without scaling), just select the item through code and then moveSelection(0, 0).

 

Hope that helps.

Link to comment
Share on other sites

I'm rushing against a deadline too, so I don't have time to explain it all, but I'll offer the following thoughts:

 

1) It depends on where your origin is for your scale. If it's in the upper left of the object (the default for TextFields) and the TextField exceeds the boundaries on the left or top sides, it won't matter how much you scale it down - it will never get it back within the boundaries. You'd have to move it too.

 

2) To trigger the bounds sensor and have TransformManager move it back within the bounds (if possible without scaling), just select the item through code and then moveSelection(0, 0).

 

Hope that helps.

 

Hi again.

 

I decided to go back to basics and simply remove and add-back to the same bounds. With an image all is fine, but on the textfield, when I select it the text shoots off to the left and the handles are in the same place. On deselecting and the reselecting the textfield has changed position. Any ideas why this has happened? I wrote a small test to see if it was out of bounds and it isn't.

 

Thanks

Link to comment
Share on other sites

*UPDATE*

 

Jack, our application is pretty big now, so it is hard to determine exactly what is going on easily here, however I thought I should let you know that I did find the problem with the textField shifting (my previous post).

 

If I set autoSize on the textField and I declare a width, the off axis issue appears, however if I do not declare a width, the issue vanishes. e.g.

 

var t = new AssetText();
			t.type = TextFieldType.INPUT;
			//t.width = (_preview.width - _textboxPadding); // IF I UNCOMMENT THIS LINE, THE TM HANDLES AND TF POSITION WILL BE COMPLETELY OFF
			//t.height = (_preview.height - _textboxPadding); // IF I UNCOMMENT THIS LINE, THE TM HANDLES AND TF POSITION WILL BE COMPLETELY OFF
			t.autoSize = TextFieldAutoSize.CENTER;
			t.multiline = true;
			t.useRichTextClipboard = false;
			t.wordWrap = true;
			t.maxChars = 100;
			t.embedFonts = true;
			t.antiAliasType = AntiAliasType.ADVANCED;
			t.sharpness = 100;

Link to comment
Share on other sites

You're using Flex, right? There are numerous bugs in the Flex framework, and that's one of them - it forces text inside TextFields to scale proportionally. Very annoying indeed. I have spoken with Adobe about several of these types of bugs and they acknowledge it's their fault and promised they'd be fixed in Flex 4.

Link to comment
Share on other sites

You're using Flex, right? There are numerous bugs in the Flex framework, and that's one of them - it forces text inside TextFields to scale proportionally. Very annoying indeed. I have spoken with Adobe about several of these types of bugs and they acknowledge it's their fault and promised they'd be fixed in Flex 4.

 

Actually using Flash CS4 with Flash player 9.

Link to comment
Share on other sites

Not sure how relevant it is, but my TextField is actually a class that inherits from TextField. (AssetText)

Link to comment
Share on other sites

Oh, if you alter the transformation properties directly AFTER adding your DisplayObject to TransformManager, it has no way of knowing that you made the changes and acts as though you didn't - you must update() the TransformItem to force it to recognize the changes you made.

 

myManager.getItem(myObject).update();

 

Does that solve it for you? If not, feel free to e-mail me an FLA that demonstrates the problem.

Link to comment
Share on other sites

Oh, if you alter the transformation properties directly AFTER adding your DisplayObject to TransformManager, it has no way of knowing that you made the changes and acts as though you didn't - you must update() the TransformItem to force it to recognize the changes you made.

 

myManager.getItem(myObject).update();

 

Does that solve it for you? If not, feel free to e-mail me an FLA that demonstrates the problem.

 

Hey there.

 

I don't update any of the dimensions. I simply remove it from the stage and then add it back later (followed by adding it to the new transformmanager).

I only set the width as above when I create the instance of the textField. Everything looks as it should until I click on it and then the text shifts.

Link to comment
Share on other sites

1) Do you remove it from the old TransformManager before adding it to the new one?

 

2) Could you send a sample FLA (as simple as possible) that demonstrates the issue?

Link to comment
Share on other sites

1) Do you remove it from the old TransformManager before adding it to the new one?

 

2) Could you send a sample FLA (as simple as possible) that demonstrates the issue?

 

Hi again.

 

I do remove it before adding a new one using the destroy() method. I have a method in my Product Class (AddAsset($asset:DisplayObject):void). This handles both Images and Textfields but the only issue is with the textField DisplayObjects. The Images appear to come in fine. As long as I remove the width and height of the textField everything appears to work, however I now need to reload the textField information from a web service, so it may lead to complications if I cannot declare this information. I will keep you posted.

 

Regarding the FLA, it is a bit difficult to do a simple fla as it is now quite a large class library.

 

Thanks for your help so far.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×