Jump to content
Search Community

crunchie

Members
  • Posts

    15
  • Joined

  • Last visited

Posts posted by crunchie

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

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

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

  4. *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;
    

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

  6. 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]

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

  8. I am using a slider component to scale my transform item, however my (poor) calculation as to what max width and height could be for the item is flawed and the max width or height ends up bigger than it should be when i set the slider to max.

     

    I believe that i need to compare the transform bounds to the items bounds and work it out from there. Unfortunately, i am not well versed in geometry and was hoping that someone could shed some light on how to do this based on the current rotation / scale of the transform item.

     

    Thanks very much,

     

    Dave

  9. Ok, got it now :)

     

    /*
    		transformManagerSelectedItemChanged
    		Description: When an item is selected via the transform manager
    	*/
    	public function transformManagerSelectedItemChanged($e:TransformEvent):void {
    
    			trace("\n\nTransformManager Items selected: " + $e.items.length);
    
    			// Loop through selected list, get original type and 
    			// process accordingly
    			for(var i=0; i<$e.items.length; i++)
    			{
    				var d:DisplayObject = $e.items[i].targetObject;
    				trace(d is AssetImage); // True
    				if(d is AssetImage)
    				{
    					// dispatch AssetImage selected event.
    				}
    
    			}
    	}
    

     

    Thanks for all your help,

     

    crunchie

  10. I don't think this has to do with TransformManager/TransformItem. It sounds like you have a function that accepts a DisplayObject (or a variable that's typed as a DisplayObject), but you're passing it a TransformItem. It also seems like the code that's throwing the error is not what you've included in your post. Could you identify the specific line that's throwing the error?

     

    Hi again.

     

    Maybe by posting this code i am over complicating the question?

    I simply want to loop through the Transform items on TransformEvent.SELECTION_CHANGE and get each TransformItem's original type, whether that be a Movieclip, Textfield or AssetImage. Is there anyway i can do this? The error is in the TransformEvent.SELECTION_CHANGE handler when i try and get the targetobject:-

     

    	/*
    		transformManagerSelectedItemChanged
    		Description: When an item is selected via the transform manager
    	*/
    	public function transformManagerSelectedItemChanged($e:TransformEvent):void {
    
    			trace("\n\nTransformManager Items selected: " + $e.items.length);
    
    			// Loop through selected list, get original type and 
    			// process accordingly
    			for(var i=0; i<$e.items.length; i++)
    			{
    				// The following line will throw an error
    				// TypeError: Error #1034: Type Coercion failed: cannot convert gs.transform::TransformItem@1d17c0e9 to flash.display.DisplayObject.
    				trace(_manager.getItem($e.items[i]).targetObject);
    			}
    	}
    

     

    I can add any type to the transform manager and it will throw that error.

     

    	// Once asset is loaded and added to stage, add it to
    	// the transform manager and initialise it.
    	public function addAssetToTransformManager(a:AssetImage):void
    	{
    		// Init with transform manager
    		_manager.addItem(a);
    	}
    

  11. If I understand your goal correctly, you'd need to access the targetObject property of the TransformItem, like:

     

    var g:* = _manager.getItem($e.items[i]).targetObject;

     

    Does that help?

     

    Thanks for the quick reply. Unfortunately i still get "TypeError: Error #1034: Type Coercion failed: cannot convert gs.transform::TransformItem@1cb050e9 to flash.display.DisplayObject."

     

    To explain what i am trying to achieve another way, i have added added my AssetImage to the transformmanager instance like so (where d is an AsssetImage or AssetText):-

     

    public function addAssetToTransformManager(d:DisplayObject):void
    	{
    		// Init with transform manager
    		_manager.addItem(d);
    
    		// Set min scale on Asset for transform manager
    		var b:TransformItem = _manager.getItem(d);
    		b.minScaleX = 0.1;
    		b.minScaleY = 0.1;
    	}
    

     

    Once any of these items is selected in the TransformManager, i wish to dispatch an event based on its original type:-

    i.e.

     

    if (g is AssetImage)
    {
     dispatchEvent(AssetEvent.ASSETIMAGE_SELECTED);
    }
    
    if (g is AssetText)
    {
     dispatchEvent(AssetEvent.ASSETTEXT_SELECTED);
    } 
    

     

    So in essence, i want to know the original type of the TransformItem. Possibly i am going about this the wrong way?

     

    Thanks a lot,

     

    crunchie

  12. Hi there.

     

    I need to get the original class type from the selected transform item.

    I am doing something like this but it errors with:-

     

    TypeError: Error #1034: Type Coercion failed: cannot convert gs.transform::TransformItem@1cb050e9 to flash.display.DisplayObject.

     

    _manager.addEventListener(TransformEvent.SELECTION_CHANGE, transformManagerSelectedItemChanged);
    
    
    	public function transformManagerSelectedItemChanged($e:TransformEvent):void {
    
    			trace("\n\nTransformManager Items selected: " + $e.items.length);
    
    			// Loop through selected list, get original type and 
    			// process accordingly
    			for(var i=0; i<$e.items.length; i++)
    			{
    				var g:* = _manager.getItem($e.items[i]);
    				if(g is AssetImage)
    				{
    					// Process AssetImage
    					trace("Selected Item Type is: AssetImage");
    				}
    				if(g is AssetText)
    				{
    					// Process AssetText
    					trace("Selected Item Type is: AssetText");
    				}
    			}
    	}
    

     

    AssetImage and AssetText both inherit from MovieClip and simply have additional properties.

     

    Thanks in advance,

     

    crunchie

×
×
  • Create New...