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
Hi, I am having issue during period end closing. Settlement say no accrued amount found for settlement. But when I see report project has the following values, (rev)-2000 (cost)1500 Total=  -500 Should these costs/ rev need to be settled some where a [More]
I have built a site offline that works absolutely fine in Safari, but when opening in Firefox the browser seems to totally ignore much of the CSS; text changes to default colors, font size alters and some alignment gets messy. Workign on a Mac, I ass [More]
I want to create a form in pages that I can then save as a pdf to load on my website so my clients can download and fill in the fields without messing with the overall formate of the sheet.Sorry, not sure I am clear. I want a form w/ name, address, e [More]
hi..... i want to know all about process for cost of goods sold,cost of manufacture,cost of production. Thanks & Regards Rekha sharmaFor frozen standard cost (both legal frozen standard and profit center standard), maintaining planning costing sheets [More]
Is there a way to insert a trademark symbol into the Item > Text?  It seems that registered trademark ® works but not the unregistered trademark. u2122Hi, please go through the below link it will help you to resolve your issue. You need to take help [More]
Hello everyone, I am new in labview. I would like to display the coherence function with the correct frequency scale. For instance, I want it to be as follow: FreqAxis = 0:Fs/2/(N+1):Fs/2. where Fs is the sampling frequency and N the number of sample [More]
Hi, I want to open a website file/folder created in an earlier version of iWeb into iWeb 08. How to do this and also the folder containing all the website files is on my iDisk and not on my hard drives?If you don't have the original domain.sites file [More]
Is a background colour in the toc possible?I think that is covered in  http://www.robowizard.com/RoboWizard/NewProject.htm#Downloads/Tips_and_Tricks.htm If it isn't I would guess the answer is no. See www.grainge.org for RoboHelp and Authoring tips @ [More]
Hello all. Hope someone can help me asap. I have a Canon colour copier with a Fiery. I am trying to print some slides from PowerPoint but as soon as I select to print, PowerPoint crashes. I cannot create PDF's either. Within a couple of seconds of th [More]
Hi all, just got the new MBP17 unibody Now I'm looking for a suitable Hard Suit / Case for it. I like the Crumpler Hardsuit that is available, but I do not know whether the NEW MBP will fit in a case designed for the previous model. Especially since [More]