Jump to content
Search Community

Getting a TransformItem's original class type [SOLVED]

crunchie test
Moderator Tag

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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);
	}

Link to comment
Share on other sites

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

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.
×
×
  • Create New...