Jump to content
Search Community

Why isn't there a deleteItem function?

ftoledo test
Moderator Tag

Recommended Posts

Hello Jack,

 

First of all, I bought the TransformManager about a week ago and I am really impressed on performance and ease of use, as with all your classes. Congratulations :)

 

I wanted to ask you why there isn't a deleteItem() and deleteItems() method, just as selectItem() and selectItems() work. I'm just wondering why you have to select an item first and then use deleteSelection(). You can see the handles when you try to delete an item using a function rather than the delete key for a split second.

 

I tried modifying your class to merge selectItem and deleteSelection but for some reason it always returns the item as null, even if I dispatch the function on an object already added to the TransformManager

 

public function deleteItem($item:*):void {
var item:TransformItem = findObject($item); //makes it possible to pass in DisplayObjects or TransformItems
if (item == null) {
	trace("TransformManager Error: deleteItem() and deleteItems() only work with objects that have a TransformItem associated with them. Make sure you create one by calling TransformManager.addItem() before attempting to select it.");
} else {
	item.deleteObject();
}
}

 

Any ideas on how to do this? Even if I need to hide the handles that would be fine, but I can only change the handleFillColor and lineColor to uint, I can't control their alpha or visibility.

 

Thank you! Congratulations again on this amazing class!

Fernando Toledo

Link to comment
Share on other sites

Hello again,

 

Actually, after doing some more testing I've found out that for some reason selectItem() doesn't work either. It always returns the trace error:

 

TransformManager Error: selectItem() and selectItems() only work with objects that have a TransformItem associated with them. Make sure you create one by calling TransformManager.addItem() before attempting to select it.

 

If I call the method in the same function where I'm instantiating the object it works fine. The object gets instantiated and selected, such as:

 

public function createItem():void
{
var object:Sprite = new Sprite();
addChild(object);
_manager.addItem(object);
_manager.selectItem(object);
}

 

But if I call the method outside the function, for example if I load an image and call it when the image is loaded (so that the handles are the real size of the sprite) it throws that trace error, like this:

 

//I insantiate the object here
public function createItem():void
{
var object:Sprite = new Sprite();
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(new URLRequest("myImage.png"));
object.addChild(loader)
addChild(object);
_manager.addItem(object);
}

//And I call the selectItems method here
private function imageLoaded(e:Event):void
{
_manager.selectItem(e.currentTarget.content.parent); //this throws the trace error
}

 

Is this a limitation or am I using the method wrong?

 

Thank you!

- ftoledo

Link to comment
Share on other sites

wow... I should probably post EOD only, instead of posting 100 times every time I found out something...

 

I think it's working now, I missed a parent in my "e.currentTarget.content.parent.parent"

 

:? I'll redo my functions and check if I can make my Frankensteinish deleteItem() method work.

 

- ftoledo

Link to comment
Share on other sites

I think it's working now, I missed a parent in my "e.currentTarget.content.parent.parent"

 

:) Thanks for at least posting that you figured it out. Yeah, deleteItem() is probably a good idea, although you should be able to do manager.getItem(myObject).deleteObject(). Your deleteItem() code looked fine to me, so I suspect it'll work fine for you once you add your other "parent" into the mix :)

 

Glad to hear you're [mostly] enjoying TransformManager. Let me know if you need anything else.

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