Jump to content
Search Community

Colorpicker Component and TransformManager

BernalCarlos test
Moderator Tag

Recommended Posts

Hello,

 

Once again here i am asking for help.

 

I'm trying to add the Colorpicker component to the list of ignored objects in the TransfromManager.

 

I read some post on the forum, and Jack suggest to set the autoDeselect property to false, and add a background sprite that handles the deselect click.

 

However, in the current state of my project doing that would involve a LOT of changes and i'm actually tacking advantage of the autoDeselect property.

 

Is there another way i can add the color picker to the ignore objects?

 

Thank you very much.

Link to comment
Share on other sites

Found a not so tricky Solution! :lol:

 

For some reason if you set a sprite behind the color picker, and add that background to the ignore objects, everything will work fine.

 

So all you have to do is to listen for OPEN and CLOSE events on the Colorpicker, and when the Colorpicker is opened just dynamically create a background sprite for it, add it to the stage, add it to the ignore Objects, and finally on close just remove the background.

 

Hope it help somebody.

 

Thanks Jack.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Hi, Here's what i did in code:

 

//First, create the backgorund sprite for the color picker
_colorPickerBackground = new Sprite();
var g:Graphics = _colorPickerBackground.graphics;
g.beginFill(0x000000, 0.3);
g.drawRect(0, 0, 217, 177); //I found the dimensions by trial and error
g.endFill();

//Second, add the event listener to the color picker
//My color picker is inside the _textEditor movieclip, but this is not necessary.
_textEditor.colorPicker_cp.addEventListener(Event.OPEN, onColorPickerEnter, false, 0, true); 
_textEditor.colorPicker_cp.addEventListener(Event.CLOSE, onColorPickerClose, false, 0, true);

//Third, create the listener functions
private function onColorPickerEnter(evt: Event): void{

  //Set the background x and y position
  _colorPickerBackground.x = _textEditor.x + _textEditor.colorPicker_cp.x + _textEditor.colorPicker_cp.width;
  _colorPickerBackground.y = _textEditor.y + _textEditor.colorPicker_cp.y;

  //Add the background to the ignore list
  _transManager.addIgnoredObject(_colorPickerBackground);

  //Finally, add the background behind the color picker. In my case, behind the _textEditor
  _mainStage.addChildAt(_colorPickerBackground, _mainStage.getChildIndex(_textEditor));

}

private function onColorPickerClose(evt: Event): void{

  //Remove the backgorund
  _mainStage.removeChild(_colorPickerBackground);
  _transManager.removeIgnoredObject(_colorPickerBackground);
  _colorPickerBackground = null
}

 

Hope it helps you.

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