Sitemap

Amicuk Programming Answers

Child is detecting click even though it shouldn't

-0001-11-30   Views:0

Advertisement

Hello once again, I technically know how to make this work right, but I'm trying to figure out what I want to do won't work right. I have a Child ("treeToChopDetect") appear when a certain other child ("sceneArray[2]") appears on stage

Hello once again,
I technically know how to make this work right, but I'm trying to figure out what I want to do won't work right.
I have a Child ("treeToChopDetect") appear when a certain other child ("sceneArray[2]") appears on stage. However, I don't want "treeToChopDetect" to be clickable until another child "guy_Bridge"/ "sceneGuyArray[2]" (the character) reaches frame "guy_AtBridgeNormal" on his own timeline.
However, "treeToChopDetect" seems to be clickable even though the "manager" function is suppose to be constantly telling the "detectArray" that mouseEnabled = false until "sceneGuyArray[2].currentLabel == "guy_AtBridgeNormal"". I keep getting a trace as output if I click on "treeToChopDetect".
I can keep it from being clickable if I set the condition to include "canClickBoo == false" (which it is until the guy reaches the right frame), but I shouldn't have to do that.
For all my other arrays I've been able to use my "manager" function to run through them (via "for" loops) and turn mouseEnabled on and off depending on if the guy is on the right frame, but something isn't working correct with this array, for some reason.
Sorry if that's confusing. I can try to clarify or add more information if necessary. (I have 600+ lines of code so of course I tried to chop out whatever I could.)
The var and array:
var treeToChopDetect:TreeToChopDetect = new TreeToChopDetect;
treeToChopDetect.x = 355;
treeToChopDetect.y = 75;
detectArray = [treeToChopDetect];
The function to detect: (if I add in canClickBoo == true to the stipulation, it runs correctly; however I don't know why I have to do this)
function detectFunction(event:MouseEvent) {
                    if (treeToChopDetect.hitTestPoint(mouseX, mouseY, true)) {
                        trace("treeToChopDetect");
These two functions are run when called in other functions, and they turn on and off the ability to click.
function canClick() {
                canClickBoo = true;
                canFunBoo = true;
            function cantClick() {
                canClickBoo = false;
                canFunBoo = false;
main function that adds/removes "outside" children and defines what canClickBoo or canFunBoo means
function manager(event:Event) {
                //listen to see what should appear
                if (stage.contains(sceneArray[2])) {
                    addChild(detectArray[0]);
                    addChild(detectArray[1]);
                } else if (!stage.contains(sceneArray[2]) && stage.contains(detectArray[0]) && stage.contains(detectArray[1])) {
                    removeChild(detectArray[0]);
                    removeChild(detectArray[1]);
                //IF canClickBoo is true, able the mouse/turn on buttonMode
                if (canClickBoo == true) {
                    ... (various other arrays get turned on)
                    for (var im:uint=0; im<detectArray.length; im++) {
                        detectArray[im].mouseEnabled = true;
                        detectArray[im].buttonMode = true;
                    //ELSE IF canClickBoo is false, disable the mouse/turn off buttonMode
                    } else if (canClickBoo == false) {
                        for (var iy:uint=0; iy<detectArray.length; iy++) {
                            detectArray[iy].mouseEnabled = false;
                            detectArray[iy].buttonMode = false;
               //if the scene and frame are correct, clicks can be heard               
                for (var jk:uint = 0; jk<sceneArray.length; jk++) {
                    if (stage.contains(sceneArray[jk])
                        && sceneGuyArray[jk].currentLabel == "guy_At"+wordArray[jk]+"Normal") {
                        //trace("canClick");
                        canClick();
                                       // else clicks can't be heard               
                    } else if (stage.contains(sceneArray[jk])
                        && sceneGuyArray[jk].currentLabel != "guy_At"+wordArray[jk]+"Normal") {
                        trace("cantClick");
                        cantClick();

The replay answer
Advertisement
Hi, tytbone;
I'm not going to sort through your logic, because, frankly, it's way too complicated. Complicated logic is hard to debug, and the way you've done it is not likely to perform well.
Try something like this:
//Not sure what class you've actually applied to the parent,
//so this name is made up
//Not applying a Class? Maybe you should start.
public class ParentClass extends MovieClip {
     //Assuming you've got these on stage an you're going to let Flash populate them
     //mainly because logic to create, add, and position things is tedious and I refuse to write it
     public var treeToChopDetect:MovieClip;
     public var guy_Bridge:MovieClip;
     public function ParentClass() {
          super();
          //added to stage doesn't bubble, use capture
          addEventListener(Event.ADDED_TO_STAGE, initNewChild, true);
     protected function initNewChild(e:Event):void {
          var newChild:MovieClip = e.target as MovieClip;
          if (newChild) {
               switch(newChild.name) {
                    case 'treeToChopDetect':
                         mouseChildren = false;
                         mouseEnabled = false;
                         break;
                    case 'guy_Bridge':
                         //find relevant frame
                         var frameNum:int = -1;
                         for each (var frameLabel:FrameLabel in newChild.currentFrameLabels) {
                              if (frameLabel.name=='guy_AtBridgeNormal') {
                                   frameNum = frameLabel.frame -1;
                                   break;
                         if (frameNum > -1) {
                              //could do this on the timeline of the child mc or with 
                              //a base class...this is just for illustration purposes
                              //tell guy at bridge to dispatch this event when he gets to the frame
                              newChild.addFrameScript(frameNum, function(){dispatchEvent(new Event('guy_AtBridgeNormal'))});
                              //listen for that event so you can unlock the tree
                              newChild.addEventListener('guy_AtBridgeNormal', unlockTree);
                    }//end case
               }//end if the child was actually a movie clip
          }//end init
          protected function unlockTree(e:Event):void {
               guy_Bridge.removeEventListener('guy_AtBridgeNormal', unlockTree);
               treeToChopDetect.mouseEnabled = true;
               treeToChopDetect.addEventListener(MouseEvent.CLICK, onTreeChop);
          protected function onTreeChop(e:Event):void {
                //do stuff

Go to See the other 6 answers

Child is detecting click even though it shouldn't

Category:DefaultRelease time:-0001-11-30Views:130

Hello once again, I technically know how to make this work right, but I'm trying to figure out what I want to do won't work right. I have a Child ("treeToChopDetect") appear when a certain other child ("sceneArray[2]") appears on stage[More]

Detecting Clicks on Lines

Category:DefaultRelease time:-0001-11-30Views:130

Hello,    I am building a canvas application that allows users to drag and drop different icons on the canvas and connect them through edges. I am using the graphics of the canvas to draw these lines. However, one of my requirements is to detect clic[More]

Detecting clicked column in JTable (with JCheckBox in column)

Category:DefaultRelease time:-0001-11-30Views:130

I am struggling with something that seems like it should be so simple, but it doesn't work as I expect; I have a table with 5 columns, the 5th column is a CheckBox. What I need to do is detect when the 5th column changes, ie. the check box is clicked[More]

Detect click and coordinates on a PDA

Category:DefaultRelease time:-0001-11-30Views:130

Hello everybody, I'm trying to detect a stylus click on a picture and the coordinates of the click on a PocketPC 2002 PDA. In the PC, this works fine with a "mouse down" event for a picture, which detects the click and the coordinates, but this[More]

Detecting Click on an MC inside an attached movieclip

Category:DefaultRelease time:-0001-11-30Views:130

I'm working with a MovieClip ("mainMenuItem") that is linked to a Class ("GenericMenuItem.as") that uses attachMovie to add another movieclip ("Arrow") to mainMenuItem as follows: mcArrow = this.attachMovie(prefix+"Arrow[More]

Detecting click ( single and double) on row (displayed using iterator)

Category:DefaultRelease time:-0001-11-30Views:130

Hello All, I am using jdev 11.1.1.6 I am displaying a list as below.                                <trh:tableLayout>                                     <af:iterator value="#{pageFlowScope.Bean.List}" var="temp">          [More]

Detecting clicks over a particular region in the frame

Category:DefaultRelease time:-0001-11-30Views:130

Hey! I need to detect whether te user clicked over a particular region in my frame.. something delimited by a poligon... or something like that.. some ideas? thank you in advance!Thx for your attention but in this case it wont work 'cause.. I didnt m[More]

Stopping the applications main window from activating when a child window is clicked

Category:DefaultRelease time:2015-10-11Views:130

I am building a javascript based AIR application that implements a bastardized growl notifier.  When the the application is minimized or in the background you may be notified of a new message.  This part works great. The UI calls for an "X" butt[More]

Detect clicked cluster in mouse down event for clusters within multiple stacked clusters

Category:DefaultRelease time:-0001-11-30Views:130

With the help of Ben (see http://forums.ni.com/t5/LabVIEW/Determine-cluster-element-clicked-in-mouse-down-event/td-p/1245770) I could easily find out what sub-cluster had been clicked on (mouse down event) within the main cluster, by using the Label.[More]

How can i detect click on JTextField

Category:DefaultRelease time:-0001-11-30Views:130

I want do some opration on JTextField when Click on JextField how should i do that please tell me RahulQuit multi-posting and cross-posting. You've already posted this question twice in the Swing forum where it belongs.Read other 2 answers[More]

Detecting a mouse click on any (all) child components...

Category:DefaultRelease time:-0001-11-30Views:130

Hey All, I am writing a number of compound GUI elements that i want to make focusable when you click any part of them. (i.e. a JTextArea inside a JScrollPane, coupled to a JTextField to provide input to the JTextArea). Is there an easy way to detect[More]

Hot
Hello, I'm doing some select queries from odp.net against my oracle database. first i do maybe: select id, ... from table1 where id in some_collection. then I might do select id, ... from table2 where id in some_collection and id2 in some_other_colle [More]
Hi, I have got an ejb and want to change my variables which I stored in property file at Runtime. But the property file isn´t in the jar-file of my ejb... How can I add it. Or How can I change the property file without new compilation. Thanks UliHi U [More]
We are dealing with a weird issue that started after a routine maintenance window this past week.  We took our Exchange 2010 server down while we performed maintenance on our SANs.  After bring the servers back up we have developed an issue in Outloo [More]
Right after I`ve upgraded to OS X Lion and updated iTunes to the 10.4 - I have a permanent error on iTunes startup. It begans to do something (determining gapless pleyback info and some other) and crashes. Every time! It seems to be crashing right in [More]
Hello SAP Consultants, I have setup a payment term for client which is 1% disc if paid within 10 days of invoice date. On running automatic payment program F110, irrespective of no. of days, the payment program generates discount of 1%. (I am using s [More]
I've been using Lightroom 5 for a few months now. I'm using the latest version (5.4) and have been experiencing extremely slow performance in two main areas: 1) When in the Library module and I select (or scroll down to) the Publish services on the l [More]
Hi, I m making import PO and did customs MIRO. I did migo but duties like cvd CESS and other are flowing to MIGO as per MIRO but those values are  one tenth of the value posted in MIRO. Earlier everything was running correctly. But i recently added o [More]
Not sure if this is an SQL or C# question, but here it goes:  I am trying to create my first CLR assembly for SQL using C#.  I found several examples online, and am following them.  However, when I try to load my assembly into the SQL Server, I recei [More]
At the launch of my application I want to fetch a variable value we have created on the iAS server at the application's OC4J instance level and under "Server Properties". I am unable to fetch anything using getHttpServletRequest() method. Does a [More]
I bought export pdf and didn't mean to... can I return it?I understand that you would like to cancel the Adobe ExportPDF Annual purchased on Aug. 05, 2014 11:26:29 AM PDT. Please confirm the date of purchase, I shall get it cancelled as well as refun [More]