Jump to content
Search Community

Changing color of selected item

hano test
Moderator Tag

Recommended Posts

Hi

 

I'm trying to make an interactive whiteboard for kids, when the click on any shape from the menu a duplicate is added on the stage that can be transformed

 

example of square adding function:

 

square_mc.addEventListener(MouseEvent.CLICK, addSquare);


function addSquare(e:MouseEvent):void {
newSquare = new Square();
newSquare.x = stage.x/2 + stage.width/2;


addChild(newSquare);
manager.addItem(newSquare);
manager.selectItem(newSquare);

 

and each new shape added is the selected one

 

what i'd like to do is change the color of the selected item by clicking on a color palette , im currently using this code but its not working

 

 

function changetored(e:MouseEvent)
{

TweenMax.to(manager.selectedItems, 1, {tint:0x000000});

}

 

any clues as to where I'm wrong?

 

thanks!

Link to comment
Share on other sites

If you want to tween an array of objects to the same end values, you'd use allTo(), not to(). And you need to affect the selectedTargetObjects, not the selectedItems (selectedItems is populated with TransformItem instances, not the actual target DisplayObjects).

 

function changetored(e:MouseEvent):void {
  TweenMax.allTo(manager.selectedTargetObjects, 1, {tint:0x000000});
}

Link to comment
Share on other sites

Thanks, I tried that, but its not working. Is "manager.selectItem" suffice to make sure the item is selected? Or is there another function I need to add?

 

I guess my question is how do I know which items are already on the stage and selected?

Link to comment
Share on other sites

manager.selectItem() will select a particular item, yes. You can use manager.selectItems() to select more than one.

 

If TweenMax.allTo(manager.selectedTargetObjects, 1, {tint:0x000000}); isn't working, I'd need to see your code - I wonder if you're calling that AFTER a click has deselected everything, so selectedTargetObjects is empty? Have you tried tracing out the length of the resulting array?

Link to comment
Share on other sites

I think I don't have a selectedTargetObjects array, I suppose that's my problem? I'm not sure how to create one :/ I don't want all the shapes on the stage to change color, just the ones that are selected (handles on them)

 

var newSquare:MovieClip;
var newTriangle:MovieClip;

var manager:TransformManager = new TransformManager({bounds:new Rectangle(0, 10, 800, 600)});

square_mc.addEventListener(MouseEvent.CLICK, addSquare);
Triangle_mc.addEventListener(MouseEvent.CLICK, addTriangle);


function addSquare(e:MouseEvent):void {
   newSquare = new Square();
   newSquare.x = stage.x/2 + stage.width/2;
   newSquare.y = square_mc.y;

   addChild(newSquare);
   manager.addItem(newSquare);
   manager.selectItem(newSquare);
   
}

function addTriangle(e:MouseEvent):void {
   newTriangle = new Triangle();
   newTriangle.x = stage.width/2;
   newTriangle.y = stage.height/2;

   
   addChild(newTriangle);
   manager.addItem(newTriangle);
   manager.selectItem(newTriangle);    
   
}


colorpicker_mc.addEventListener(MouseEvent.CLICK, changetored);


function changetored(e:MouseEvent)

{
   TweenMax.allTo(manager.selectedTargetObjects, 1, {tint:0x000000});
   
}

Link to comment
Share on other sites

No no, you don't need to create a selectedTargetObjects array - that's something you can ask the TransformManager anytime. It spits back an array containing all the targetObjects that are currently selected. Try putting this above your TweenMax call:

 

trace(manager.selectedTargetObjects.length);

 

Is it 0? If so, that means nothing is selected. Keep in mind that by default, autoDeselect is true, so when the user clicks off of one of the selected objects, it will deselect it. So, for example, let's say the user selected an object and then click on your

colorpicker_mc component/MovieClip - that would immediately cause the object to be deselected. See what I mean? If you'd like TransformManager to ignore clicks on colorpicker_mc, you can add it as an ignoredObject, like:

 

manager.addIgnoredObject(colorpicker_mc);

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