Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do you click on object and then unclick that onbject to then click on another object?

New Here ,
Feb 25, 2012 Feb 25, 2012

I am building a simple game in which you must click on a square to activate it, meaning when you click on it you have control of its movement. I then want to be able to click on the square again so that you don't have control of it, and then you can click on another object in the game. What is the code to allow this? I believe its an eventListener for a mouse event.

TOPICS
ActionScript
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 25, 2012 Feb 25, 2012

Clicking either way involves assigning an event listener for the CLICK event, as in...

yourSquare.addEventListener(MouseEvent.CLICK, manageControl);

wherein bth the name of the square that I used (yourSquare) and the name of the event handler function (manageControl) are named however you want them named.  The real work gets done in the event handler function...

function manageControl(evt:MouseEvent):void {

     // this is where your code will go to determine if the square has been clicked to contro

...
Translate
LEGEND ,
Feb 25, 2012 Feb 25, 2012

Clicking either way involves assigning an event listener for the CLICK event, as in...

yourSquare.addEventListener(MouseEvent.CLICK, manageControl);

wherein bth the name of the square that I used (yourSquare) and the name of the event handler function (manageControl) are named however you want them named.  The real work gets done in the event handler function...

function manageControl(evt:MouseEvent):void {

     // this is where your code will go to determine if the square has been clicked to control it versus clicked to give up control.

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2012 Feb 25, 2012

I got that to work, except I can't unclick. When I click on an object the user has control of it, and then when they click on another object they control both of them at once.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 25, 2012 Feb 25, 2012
LATEST

That is not the situation you originally described.  You wanted to know how to deal with clkicking the same object and having it controlled versus not controlled depending on what state it is currently in.

If you want clicking another object to disabkle the control of another, then you need to have something store the information as to what object is currently under control so that you can discontinue its control... OR... have a function that disables all objects that you call first when you click an object, then set the control for the clicked object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines