Jump to content
GreenSock

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

Transforming inputField [SOLVED]

Recommended Posts

Hi There,

 

The company where i work just bought the TransformManager (as3) and i have a question about transforming inputfields.

I add a inputfield with the following function:

 

//-PUBLIC & INTERNAL METHODS -------------------------------------------------------------------
	public function addText(str:String = "Typ hier je tekst") {	
		var txt:TextField = new TextField();
		txt.defaultTextFormat = defaultFormat;
		txt.embedFonts = true;
		txt.autoSize = TextFieldAutoSize.LEFT;
		txt.type = TextFieldType.INPUT;
		txt.multiline = true;
		txt.text = str;
		txt.mouseEnabled = true;
		txt.selectable = true;
		stage.focus = txt;
		txt.addEventListener(MouseEvent.CLICK,selectObject)
		txt.setSelection(0, txt.text.length);
		objectHolder.addChild(txt)
		manager.addItem(txt)
	}

 

But when i want to scale the TextField i get the following result:

post-323-133151999594_thumb.jpg

 

As you can see the textField wont scale/update the text.

Does anyone have a solution?

 

Edit:

I found out the problem has to do with the display list stated in this topic : http://forums.greensock.com/viewtopic.php?f=3&t=175

How can i reparent my TransformManager?

 

 

Greetz WS

Link to comment
Share on other sites

TransformManager defines its parent the first time you add an item to it. If you're going to reparent the item(s), I'd recommend just creating a new TransformManager instance for that new parent. Just destroy() the first TransformManager and create a new one and add your item(s) to it for the new parent. Does that answer your question?

Link to comment
Share on other sites

Hey Greensock,

 

Thanks for the quick response!

 

Here's the code im using to add DisplayObjects to my Canvas

I made a class named ObjectHolder where i want to place my inputfields and images.

Images transform perfect(1) the only problem i get is when i want to transform a textfield(2)

I can rotate the textfield but when i want to scale the textfield and automaticly update the text (like your demo)it resets to its orginal box(3).

Am i doing something wrong?

 

(1)post-323-133151999596_thumb.png

(2)post-323-133151999603_thumb.png

(3)post-323-133151999606_thumb.png

 

Canvas Class:

 

public function addText(str:String = "Typ hier je tekst") {

		var txt:TextField = new TextField();
		txt.defaultTextFormat = defaultFormat;
		txt.embedFonts = true;
		txt.autoSize = TextFieldAutoSize.LEFT;
		txt.type = TextFieldType.INPUT;
		txt.multiline = true;
		txt.text = str;
		txt.mouseEnabled = true;
		txt.selectable = true;
		stage.focus = txt;
		txt.addEventListener(MouseEvent.CLICK,selectObject)
		txt.setSelection(0, txt.text.length);






	}

 

ObjectHolder Class:

 

package com.wsvdmeer.ui{
import flash.display.Sprite;
import com.gs.transform.*;
import com.gs.events.TransformEvent;
import flash.display.DisplayObject;
import flash.display.Sprite;

public class ObjectHolder extends Sprite {

	private var manager:TransformManager;

	public function ObjectHolder() {

		manager = new TransformManager({

		  arrowKeysMove:true,
		  forceSelectionToFront:false,
		  allowMultiSelect:true,
		  allowDelete:true,
		  handleSize:8

		  });

	}
	public function add(obj:DisplayObject) {
		addChild(obj);
		trace(obj)//traces [object TextField]
		manager.addItem(obj);
	}

	public function scale(scale:Number) {
		manager.handleSize = 8/scale;
	}
}
}

Link to comment
Share on other sites

I didn't see where/how you're handling reparenting (if at all). You problem may be related to that.

 

Please keep in mind that there is a BUG in the Flex Framework (not TransformManager) that won't let you scale TextFields disproportionately (I mention this on the TransformManager page and documentation). You're using Flex, right? (you mentioned "Canvas", so I assume you're working in Flex).

Link to comment
Share on other sites

I didn't see where/how you're handling reparenting (if at all). You problem may be related to that.

 

Please keep in mind that there is a BUG in the Flex Framework (not TransformManager) that won't let you scale TextFields disproportionately (I mention this on the TransformManager page and documentation). You're using Flex, right? (you mentioned "Canvas", so I assume you're working in Flex).

 

Hey GreenSock,

 

I Chose not to reparent because i thought i could fix the problem by putting the TransformManager and the text/image objects in one Class(ObjectHolder).

This way they all share the same parent (ObjectHolder).

I'm not using flex for my application Canvas is just the name of the users designspace where they can add images and text objects and transform them.

Link to comment
Share on other sites

So your TextField is being altered independently AFTER it was added to TransformManager? For example, maybe the size is 100, 100 when it gets added, but then later the user (or you through code) alter the size without going through TransformManager? You should either make all your transformations through TransoformManager OR just make sure you call update() on the TransformItem instance associated with your TextField between the time it was altered and the time it gets selected because TransformManager doesn't "watch" the object to see if you make any changes independently of TransformManager.

 

If that doesn't help, could you post a super-simple FLA that demonstrates the problem? Please strip out all unnecessary code.

 

I'm sure we can get it figured out :)

Link to comment
Share on other sites

Hey Greensock,

 

I added the test fla with the stripped code and removed the transformation classes from the gs folder.

I hope you can solve my problem :D .

 

[attachment=0]Test.rar[/attachment]

Link to comment
Share on other sites

Oh, I think I see the problem. Two things to keep in mind:

 

1) When you transform TextFields, TransformManager will change the size of the BOX, not the text. This is actually a feature. If you want the text to transform with the box/handles, just wrap your TextField in a Sprite/MovieClip.

 

2) You set your TextField to autoSize which explains why it won't allow TransformManager to go smaller than the text - Flash just resizes the TextField immediately to fit the contents.

 

Does that help?

Link to comment
Share on other sites

Hey Greensock that helped a lot! i removed autoSize and it works perfect.

Thank you!:D

 

PROBLEM SOLVED :D

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.
×