Dcoo

Can I add a listener for any time a manager Item is selected?

Recommended Posts

I would like to trigger an event when the user clicks no an item in my TransformManager list, but I cant figure out what to listen for?

 

here are some things I've tried:

 

listener('add', manager);    

 

listener('add', manager.selectedItems);

 

======

So this works but obviously it heres all the other objects on stage if the user clicks them :)

 

listener('add', this.stage);
 

========

Share this post


Link to post
Share on other sites

You can just add CLICK or MOUSE_DOWN or MOUSE_UP listeners to individual DisplayObjects. You don't need to do anything special just because you're using TransformManager. 

yourObject.addEventListener(MouseEvent.CLICK, yourFunction);

Or perhaps I misunderstood your question.

Share this post


Link to post
Share on other sites

You can just add CLICK or MOUSE_DOWN or MOUSE_UP listeners to individual DisplayObjects. You don't need to do anything special just because you're using TransformManager. 

yourObject.addEventListener(MouseEvent.CLICK, yourFunction);

Or perhaps I misunderstood your question.

let me try and explain it better, I have objects that are dynamically added to my managaer and something like 40 other possible items add by the user from the library, so I'm thinking if there was a way to add a listener for anything that comes on the stage thats has already been added to my manager,and  if the user clicks it bingo!

kinda like "manager.deleteSelection(); "

Share this post


Link to post
Share on other sites

Sorry, I read your response 3 times and I'm still fuzzy about why my answer didn't suffice. It doesn't seem like a TransformManager question, but rather a general AS3 question. Hm. 

 

I guess the only other thing I'd add is that you can do something like yourManager.addEventListener(TransformEvent.SELECTION_CHANGE, yourFunction) to find out whenever the selection changes. 

Share this post


Link to post
Share on other sites

Ok let me ask you this then, is there a way to see if an object has been add to the manager ? I want to trigger something but only if the selection has been added to the manager.

Share this post


Link to post
Share on other sites

Wouldn't you be the one adding it? I'm confused - this seems like an architecture issue with your code, or maybe I'm misunderstanding the question. If you want to know if an object is being managed by a particular TransformManager, you could use the getItem() method, but it seems to me like you should just add logic to your code where you'd be adding it in the first place, so you set a flag/variable there. Sorry if I misunderstood.

Share this post


Link to post
Share on other sites

The user will be adding objects and images to the stage, but I only want to trigger actions when items that have been added to the manager are selected. Like this. that way its the only parameter I need to listen  for.

trace( "Synchronous media promise." );imageLoader.loadFilePromise( imagePromise );
this.addChild( imageLoader );

manager.addItem(imageLoader);

Share this post


Link to post
Share on other sites

I'm probably still misunderstanding, but if you want to know when a particular item is selected you could do:

var item:TransformItem = yourManager.getItem(yourObject);
item.addEventListener(TransformEvent.SELECT, yourHandler);

Is that what you're looking for? 

Share this post


Link to post
Share on other sites
I want to know if an object on stage is has been added to a particular  manager, if so preform function listen_for_manager using action:String  this code below obviously does not work, but something like this is what I'm trying to do



listen_for_manager('add', stage.manager);         

function listen_for_manager(action:String, target:IEventDispatcher):void
{
if (action == 'add'){
  //do something}

Share this post


Link to post
Share on other sites

So I pushed all manager objects into a holder_mc and add listen_for_manager - holder_mc.stage and it works!  oh so happy now! :) 
 

listen_for_manager('add', holder_mc.stage);

function listen_for_manager(action:String, target:IEventDispatcher):void
{
if (action == 'add'){
  //do something}

Share this post


Link to post
Share on other sites

Spoke too soon, it listens for any object on stage still :( 

Share this post


Link to post
Share on other sites

Sorry, I'm still really struggling to understand how to help you here. I want to help, I just can't figure out what exactly you're asking or why you're doing what you're doing. :(

 

If you want to know when a particular DisplayObject is added to the stage, there's an Event.ADDED_TO_STAGE event type (which has nothing to do with TransformManager - that's just Flash). 

Share this post


Link to post
Share on other sites

well I'm not looking for a particular DisplayObject I'm looking for all DisplayObject that have been added to my manager and only them, so it seems like I should be able to access that list somehow, but if not, oh well

 

cheers :)

Share this post


Link to post
Share on other sites

Maybe look into Flash's Event.ADDED event. Can't remember if it bubbles. Might help, might not. You can loop through the children using numChildren and getChildAt().

Share this post


Link to post
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.