tonilopez

Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

0 Newbie

About tonilopez

  • Rank
    Newbie
  1. Following your advice I have written two solutions, I posted the code, I hope it can be useful to someone. Solution 1 (the very ease way): import com.greensock.transform.TransformManager; import com.greensock.transform.TransformItem; import com.greensock.events.TransformEvent; import flash.display.Sprite; import flash.text.TextField; import flash.events.Event; var _sprite:Sprite; var _textField:TextField; var _manager:TransformManager; var _item:TransformItem; _sprite = new Sprite() ; addChild (_sprite); _textField = new TextField(); _textField.multiline = true; _textField.wordWrap = true; _textField.type = TextFieldType.INPUT; _textField.border = true; _textField.text = 'Texto'; _sprite.addChild (_textField); _manager = new TransformManager(); _item = _manager.addItem(_sprite,TransformManager.SCALE_WIDTH_AND_HEIGHT,true); _item.addEventListener (TransformEvent.SCALE, onUpdateItem); function onUpdateItem (event:Event):void { _textField.width = event.target.width; _textField.height = event.target.height; } Solution 2 (The most sophisticated ) Main.as package com{ import com.greensock.transform.TransformManager; import com.greensock.transform.TransformItem; import com.CustomSprite; import com.CustomEvent; import flash.text.TextField; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextFieldType; import flash.display.Sprite; public class Main extends Sprite { var _textField1:TextField = new TextField(); var _textField2:TextField = new TextField(); var _customSprite:CustomSprite; var _customSprite2:CustomSprite; var item1:TransformItem; var item2:TransformItem; var _manager:TransformManager; public function Main () { _textField1.multiline = true; _textField1.wordWrap = true; _textField1.type = TextFieldType.INPUT; _textField1.border = true; _textField1.text = 'Texto'; _textField2.multiline = true; _textField2.wordWrap = true; _textField2.type = TextFieldType.INPUT; _textField2.border = true; _textField2.text = 'Texto 2'; _customSprite = new CustomSprite ; addChild (_customSprite); _customSprite.target = _textField1; _customSprite2 = new CustomSprite ; addChild (_customSprite2); _customSprite2.target = _textField2; _manager = new TransformManager(); item1 = _manager.addItem(_customSprite,TransformManager.SCALE_WIDTH_AND_HEIGHT,true); item2 = _manager.addItem(_customSprite2,TransformManager.SCALE_WIDTH_AND_HEIGHT,true); _customSprite.addChild (_textField1); _customSprite.addEventListener (CustomEvent.WIDTH_CHANGED, widthChangedListener, false, 0, true); _customSprite.addEventListener (CustomEvent.HEIGHT_CHANGED, heightChangedListener, false, 0, true); _customSprite2.addChild (_textField2); _customSprite2.addEventListener (CustomEvent.WIDTH_CHANGED, widthChangedListener, false, 0, true); _customSprite2.addEventListener (CustomEvent.HEIGHT_CHANGED, heightChangedListener, false, 0, true); _customSprite2.x = 250; } private function widthChangedListener (event:CustomEvent):void { event.target.target.width = event.target.width; } private function heightChangedListener (event:CustomEvent):void { event.target.target.height = event.target.height; } } } CustomSprite.as package com{ import flash.display.Sprite; import flash.events.Event; import com.CustomEvent; import flash.text.TextField; public class CustomSprite extends Sprite { private var _target:TextField; public function CustomSprite () { super (); } override public function set width (value:Number):void { super.width = value; dispatchEvent (new CustomEvent(CustomEvent.WIDTH_CHANGED)); } override public function get width ():Number { return super.width; } override public function set height (value:Number):void { super.height = value; dispatchEvent (new CustomEvent(CustomEvent.HEIGHT_CHANGED)); } override public function get height ():Number { return super.height; } override public function dispatchEvent (event:Event):Boolean { if (willTrigger(event.type)) { return super.dispatchEvent(event); } return true; } public function set target(target:TextField):void{ _target = target } public function get target():TextField{ return _target; } } } CustomEvent.as package com { import flash.events.Event; public class CustomEvent extends Event { public static const WIDTH_CHANGED:String = "widthChanged"; public static const HEIGHT_CHANGED:String = "heightChanged"; public function CustomEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) { super(type, bubbles, cancelable); } override public function clone():Event { return new CustomEvent(type, bubbles, cancelable); } override public function toString():String { return formatToString("CustomEvent", type, bubbles, cancelable, eventPhase); } }}
  2. Thanks for the reply, indeed had not understood the documentation. [Deleted example because it contained TransformManager files, thus granting free access to anyone in the forums] Sorry about this, I had not thought of. Regards
  3. Hello, I have difficulty using the TransformManager.SCALE_WIDTH_AND_HEIGHT feature. Perhaps I have not understood the documentation or this is not the mission of this feature. What I want is to scale an object containing text that the text does not scale, eg import com.greensock.transform.TransformManager; import com.greensock.transform.TransformItem; import com.greensock.events.TransformEvent; var _manager:TransformManager = new TransformManager({hasSelectableTex:true}); var item:TransformItem = _manager.addItem(textBox,TransformManager.SCALE_WIDTH_AND_HEIGHT,true);//textBox is a movieClip that contains a text field item.addEventListener (TransformEvent.SCALE, onUpdateItem); function onUpdateItem (event:TransformEvent):void { trace (textBox.width,textBox.height,textBox.scaleX,textBox.scaleY); } I appreciate your help I attach a basic example of what I try to do. [Deleted example because it contained TransformManager files, thus granting free access to anyone in the forums]