EventListener on variable change?

Wondering if it's possible and how would you go about doing it..
Upon a public variable changing in a component, it executes code.
[Bindable] is fine if I want to display the change as is.  I actually want to execute everytime the variable changes.
I tried, addEventListener but that doesn't seem to work...is this even possible.

There are a few main ways you could do this. Let's assume the variable is named chess and is of the datatype Game
1. ChangeWatcher ... moving on
2. Or you could write your code like this.
   private var _chess:Game;
   public function set chess( value:Game ):void
        _chess = value;
       dispatchEvent( new Event("gameChanger") );
   [Bindable(Event="gameChanger")]
   public function get chess():Game
      return _chess;
   This method allows you to add an eventlistener that listens for the event "gameChanger".    Now if you want the chess game change event to bubble you may have to use a custom event.  An added advantage to this , is you can run any code you need to when the chess game changes in the set chess method.

Similar Messages

  • Functions triggered on variable change

    Hi there!
    It's surely something quite easy, but couldn't find exactly
    what I wanted; it must be related to the eventListener thing, but
    don't know how to do it:
    I'd like several movie clips to react (each one in its own
    way) when a variable changes; say I've got a website that needs to
    be editable when the var _root.vAdmin = "yes" and not when the
    latter equals "no"; so I need multiple functions situated anywhere
    to be triggered when the variable _root.vAdmin changes; any idea?
    Thanks in advance!

    seems like this is what you need. look into EventDispatcher
    or AsBroadcaster classes
    tutorial:
    http://www.kirupa.com/developer/actionscript/eventdispatcher.htm

  • Non-static variable change cannot be referenced from a static context

    My compiler says: : non-static variable change cannot be referenced from a static context
    when i try to compile this. Why is it happening?
    public class change{
      int coin[] = {1,5,10,25,50};
      int change=0;
      public static void main(){
        int val = Integer.parseInt(JOptionPane.showInputDialog(null, "Type the amount: ", "Change", JOptionPane.QUESTION_MESSAGE));
        change = backtrack();
    }

    A static field or method is not associated with any instance of the class; rather it's associated with the class itself.
    When you declared the field to be non-static (by not including the "static" keyword; non-static methods and fields are much more common so it's the default), that meant that the field was a property of an object. But the static main method, being static, didn't have an object associated with it. So there was no "change" property to refer to.
    An alternative way to get this work, would be to make your main method instantiate an object of the class "change", and put the functionality in other instance methods.
    By the way, class names are supposed to start with upper-case letters. That's the convention.

  • AS3 in timeline - variable changes value on its own

    I've just started working with Flash CS4 and Actionscript 3 after being away from Flash for almost 10 years.
    I've set up a menu that allows users to select from five sections. When users select an option, flow goes to the corresponding section of the timeline and a movieclip plays. Stop actions prevent flow from continuing past the current section. A home button takes users back to the menu in the first frame. This works just fine.
    The client wants to provide a 'next' button which should play through all sections in sequence when the learner clicks it. I've defined a variable which I set to true when the user clicks 'next'. I've added if...else logic to the stop actions:
      trace("nextClicked "+nextClicked);
      if (nextClicked == true)
          play();
      else
          stop();
    This should stop flow unless the play button has been pressed setting the variable nextClicked to true. That's not what happens - flow stops even if when I click the 'next' button. I added the trace to verify the variable has the correct value and discovered that the variable value resets to false from true before it gets to this script.
    What am I missing about ActionScript 3 that might account for this behaviour? I have tried to read the Actionscript 3 materials but I get bogged down in the complexity of the programming requirements and the lack of depth in the examples provided. I'm sure the examples are perfectly adequate if you're trying to do what they illustrate but I haven't found an example that fits what I'm trying to do here.
    Thanks.

    Thank you for your suggestion:
    I have declared the variable at the beginning. This is a sample of the code in the first frame:
    //define variable
    var nextClicked:Boolean;
    //define event listeners and the corresponding functions for menu buttons
    //Me
    btn_me.addEventListener(MouseEvent.CLICK, gotome);
    function gotome(event:MouseEvent):void {
        //set var to false to indicate Next has not been clicked
        var nextClicked = false;
        trace("Me selected "+nextClicked);
        gotoAndPlay("me");
    [.....more code defining more listeners...]
    //define listener for Next button
    btn_next.addEventListener(MouseEvent.CLICK,gonext);
    function gonext(event:MouseEvent):void {
        //set var to true to indicate Next has been clicked
        var nextClicked=true;
        trace("Clicked next "+nextClicked);
        play();
    This seems very similar to what you suggested except you also included this line:
    Button1.label = "show Var";
    and I'm not sure what that line does. Does it set a label for the button? Since I've already set these explicitly, I don't see that this would be necessary. More importantly, I don't understand why leaving this out would cause the problem I'm having - the value of the variable changes from true to false without any code being executed.
    I'm still in the dark - and I still need to solve this.
    Thanks.

  • Refresh FR report when Substitution Variable change

    Hi All,
    Is there any way to refresh FR report which are opened through smart view/ workspace when the Substitution Variable changed. Like if my report opened for the Year = Curryear and now curryear value is FY14 if I changed curryear as FY15 will it reflect on my FR report that already opened.
    Regards,
    Pradipta

    For sure it won't be updated automatically if the report is open. Did you try changing it and then see what happens?
    You'll have to refresh the report for the subvar to show up on the report.
    P.S remember to stop and start your Essbase application after the subvar change
    Regards
    Celvin Kattookaran

  • Watch object variable change in parent

    Flash CS4
    AS2
    I've been trying to use the object.watch() method.  I've never used this before, so I'm assuming I'm pretty far off base here.
    What I have is a parent movie (_root.) that has a bunch of variables.  As the user progresses through the movie/project the variables change based on the user's actions.  Within this parent movie there is another movie embedded.  In this movie, things change based on the variable changes of the parent movie.  So, for instance, say the user gets through frame #20 and hits the "next" button in the parent movie, this triggers a variable change in the parent movie, which then causes the embedded movie to change its color from blue to red (or whatever, action doesn't matter)
    var btn1:Object = new Object();
    btn1.complete = _root.btn1_comp;
    btn1.watch( "complete", watcher);
    var btn2:Object = new Object();
    btn2.complete = _root.btn2_comp;
    btn2.watch( "complete", watcher);
    function watcher( prop, oldValue, newValue, userData )
      gotoAndPlay(1);
    So this is what I'm doing right now - this is the actions in the embedded "child" movie clip.  I'm not really sure if I'm doing this right - but basically what happens is that this is suppose to watch for the variables "btn1_comp" and "btn2_comp" in the parent movie clip (at the _root.).
    Taken from an example I saw somewhere, this should assign the variable in the root to the property of the object in the child "btn1.complete" and "btn2.complete"  - but basically what I really need, is for it to watch if "_root.btn1_comp" and "_root.btn2_comp" change...
    Anyone have any ideas on how I go about doing this from here??
    The function "watcher" - is supposed to just replay the embedded movie clip - because it has a bunch of AS that changes the state of the movie clip based on the variables it pulls from the parent - but I need it to know to "replay" itself when a parent variable changes - I can't have it continuing to replay itself because that would end in a crazy endless loop.
    Thanks for the help!
    -R.J.

    Any chance anyone can offer some insight for me on which way I need to go with this?

  • Writing an ActionListener that responds when a variable changes

    I am interested in writing an ActionListener that monitors the value of a variable. When the value of that variable changes, I want the ActionLiastener to kick in and change what is displayed in a JLabel on the display. Note that there is no user interaction throughout this process.
    Has anyone done this before or have any insight? I assume that ActionListeners are the way to go, but in case they are not, is there another way?
    Thanks!

    ActionListeners, by their very nature, listen for user actions; if there is no user interaction, they won't do anything. When you update the variable, why not just update the JLable too? Just make sure you do it on the Event thread (might need to use SwingUtilities.invokeLater()) and you might need to explicitly tell it to repaint itself. Hope this helps.
    Jamie

  • Reload a method during a variable change

    I want to run a method when a variable changes.. Some sort of
    listener on the variable.. Something like that.. Is it possible?
    Any ideas?

    One way to do this is to use a setter function. to the
    outside, it looks just like a variable, but is really a function in
    which you can do whatever you want. It has a special format:
    [Bindable]private var _sMyString:String;
    public function set myString(sValue:String):void {
    _sMyString = sValue; //normal variable stuff
    //now do whatever special processing you need to do.
    Use this property like this
    myString = "someValue";
    or:
    this.myString = "someValue";
    or
    myClass.myString = "someValue";
    You can also look into changeWatcher()
    Tracy

  • Event handeling variable changes. Is this possible?

    Hey,
    I'm working on a java-beans project and I am trying to come to find a way to signal an event when a variable changes. Basically looking for a way to constantly send the refreshing data to the listener bean.
    I can easily get it to work send the data with pushing a button but this is supposed to monitor a constantly changing temperature and send it to the listener bean.
    Any ideas?
    Thanks.

    Use Timer or ur own Thread.

  • Format of Variables Change When Debugging

    When debugging in LabWindows, the format of the variables (decimal, hex, ASCII, etc.) is always set to the default under certain circumstances.  For example if you step into a function, change format of a variable, step out then back in, the format has been reset to the default.  There are other instances when you run, stop, rebuild and debug where this is done also.
    I've asked NI to explain why the variable format can't be retained, at least within one debug session (until exiting LabWindows).  The explanation is they use a stack-based system to store this information so it is lost during debug.
    I find this to be an extreme annoyance and an enormous waste of time.  For example, I deal with a lot of arrays of binary data.  Seeing these array values in ASCII is of no value.  So I'm nearly constantly setting the format back to hex during debugging.
    I'm curious whether anyone else thinks this is a problem.  NI knows about this, but it's unlikely they'll do anything unless there is a lot of feedback from us users on the value of fixing this.  Post a note and let me (and NI) know what you think, whether you think this is important or not.
    Thanks,
    Dave

    Hi Chris,
    Yes, using Format >> Preferences is exactly what I was talking about when I said "change the format of a variable".  Thanks for giving the exact details of doing this.
    I'm still using v8.1.  I'm leery of renewing my service contract because I don't feel NI is listening to me (as a customer, not just a LabWindows user) regarding the issues that affect my work and ways to greatly improve my productivity.  I have been suggesting this for a few years now, to no avail, both with tech support on the phone and through your product suggestion center.
    I can't explain all the intricacies of the issue.  Maybe what you have to do is set breakpoints and run rather than step in and out.  Here's what an engineer in NI's R&D center said:
    It's not actually rebuilding the project that causes the information to be lost. It's actually even worse than that. As variables come in and out of scope, the formatting and the expand/collapse state of each variable is lost. So, if you've hit a breakpoint in a function and re-formatted a local variable, and then continue debugging outside the function, eventually stepping back into the function, the formatting for the original variable is reset when the item is created anew in the variable display, based on the data type of the variable.
    The problem we have is that the formatting information is stored in stack-based memory which is associated with the actual items that you see in the variable display. As these items disappear and are re-created in the variable display, the formatting information is reset.
    The complexity of representing variable scope information, including arbitrary block scopes, makes it pretty hard to maintain variable information in global, non-stack-based memory. It's obviously not impossible, but unfortunately it would require a fundamental redesign of our debugging paradigm.
    Finally, we have heard this request from multiple customers, and I assure you that you are not the only customer who has asked for this feature.  The problem with this feature, as with many other feature requests is one of trade-off. It is obviously impossible to accept all the feedback that we receive, and so we are constantly having to weigh development costs of a particular feature, the risks involved in implementing it, and how widespread its benefits are.  So far, this feature has not made the cut. However, this does not mean that we're ignoring it, or any other customer feedback. Many customer-requested features have made it into previous releases, and we're confident that this will too, in the not too distant future. As a matter of fact, we can honestly say that most new features in a given CVI release originate with customer requests. I also just want to re-emphasize that each time you reiterate how important a given feature is, it drives up its priority and makes it more likely that we will implement it sooner, rather than later. With that in mind, we definitely welcome your suggestion to post a note about this request in the forum. We expect other people to second the request, and the more people that do that, the better.
    So my question wasn't posted for NI to respond.  It was to find out if anybody else using LabWindows finds this issue to be detrimental to productivity.
    Thanks,
    Dave

  • Binded variables change value of modbus PLC variable when application starts

    Hello,
    I have a front panel with controls binded to some shared variables that use a modbus server to control a PLC. There is no logic behind that front panel, all I want to do is to be able to read/write some variables on the PLC.
    I binded the control with datasocket. The reason I did not use PSP is that I would like to bind the controls programmatically so if the client change the server (that holds the library and the citadel BD) the only thing he would have to do is to change the name of the server in the configuration file. It's seems that there is a bug in the Data Bindingath Property and it always return me an error when I try to bind dynamically (Which is not the case with the DataSocket:URL Property) .
    Now the PROBLEM: 
    Lets say a certains variable on the PLC holds the value 10. When I open my panel, I can see that value (10) a very short moment (milliseconds) and the value shifts to '0'. That undesirable '0' is indded written on the shared variable on the server and on the PLC. After that I can change the same value back and everything works properly. Its seems to me that the problem occurs only at the first connection. Same thing apend with booleans controls.
    I would like to be able to open my application, see the '10' in my control, update it if I want, close the application and get the last value when I re-open it.
    I'm running an executable with the DSC run-time.
    Thanks in advance for your help!
    Vincent

    Hello Vincent,
    This was reported to R&D (#161821) for further investigation.  I noticed that this only happens for controls in subVIs.  Perhaps you could restructure your program so that it no longer needs to view the front panel of its subVIs.  I will let you know if I find any other workarounds.  Thanks for the feedback!
    Regards,
    Burt S

  • Variable updating when another variable changes. How to keep it static?

    I'm missing something very basic here I think. What's happening is that I'm looping through a list. I also need to update that list, but since I don't want to update the list I'm looping through, I created a temporary list to hold the new values. Then after I'm done looping, I'll update my original list with my temporary list.
    I started out by defining/setting the variables:
    <defvar name='matchedAccessLevels'>
         <ref>
              <concat>
                   <s>user.accounts[FACILITIES].properties.locationMap[</s>
                   <ref>theLoc</ref>
                   <s>].accessLevels</s>                                                            
              </concat>                                                       
         </ref>                                                       
    </defvar>
    <defvar name='tempAccessLevels'>
         <ref>matchedAccessLevels</ref>                    
    </defvar>Then I loop through. Below are the results from the log with block trace. It looks like whenever I update tempAccessLevels, it's updating matchedAccessLevels. The whole point of using tempAccessLevels was so that matchedAccessLevels remained static. What am I missing? What do I need to do differently to keep matchedAccessLevels from changing? I've tried many different combinations of code and still matchedAccessLevels is changing whenever I update tempAccessLevels.
    <cond>
         <eq>
           <ref>theLoc</ref> --> Milwaukee
           <s>Milwaukee</s> --> Milwaukee
         </eq> --> 1
         <block trace='true'>
           <set name='matchedAccessLevels'>
              <ref>
                <concat>
                   <s>user.accounts[FACILITIES].properties.locationMap[</s> --> user.accounts[FACILITIES].properties.locationMap[
                   <ref>theLoc</ref> --> Milwaukee
                   <s>].accessLevels</s> --> ].accessLevels
                </concat> --> user.accounts[FACILITIES].properties.locationMap[Milwaukee].accessLevels
              </ref> --> [Mail Room, Provider Audit File - Door 3142, Cost Reports - Door 3127]
           </set> --> null
           <set name='tempAccessLevels'>
              <ref>matchedAccessLevels</ref> --> [Mail Room, Provider Audit File - Door 3142, Cost Reports - Door 3127]
           </set> --> null
           <dolist name='theAccessLevel'>
              <ref>matchedAccessLevels</ref> --> [Mail Room, Provider Audit File - Door 3142, Cost Reports - Door 3127]
              <cond>
                <eq>
                   <ref>theAccessLevel</ref> --> Mail Room
                   <s>Mail Room</s> --> Mail Room
                </eq> --> 1
                <block trace='true'>
                   <remove name='tempAccessLevels'>
                     <s>Mail Room</s> --> Mail Room
                   </remove> --> null
                   <ref>tempAccessLevels</ref> --> [Provider Audit File - Door 3142, Cost Reports - Door 3127]
                   <ref>matchedAccessLevels</ref> --> [Provider Audit File - Door 3142, Cost Reports - Door 3127]
                   <append name='tempAccessLevels'>
                     <s>Center Hall to NGS Far N Dr</s> --> Center Hall to NGS Far N Dr
                   </append> --> null
                   <ref>tempAccessLevels</ref> --> [Provider Audit File - Door 3142, Cost Reports - Door 3127, Center Hall to NGS Far N Dr]
                   <ref>matchedAccessLevels</ref> --> [Provider Audit File - Door 3142, Cost Reports - Door 3127, Center Hall to NGS Far N Dr]
                   <defvar name='isAccessLevelUpdated'>
                   </defvar> --> null
                </block> --> null
              </cond> --> null

    Ok, xpress objects are really Java objects and, as in Java, are handled by reference.
    When you are setting tempAccessLevels, you are setting it to refer to the same list object as matchedAccessLevels.
    A convenient way to actually copy a list is with the append function. eg:
    <defvar name='tempAccessLevels'>
    <append>
         <ref>matchedAccessLevels</ref>     
    </append>               
    </defvar>

  • UNITS have been changed while variable changes

    Hi All,
    While executing BI reports , the Units being changed in the report after change the variable for fiscal year.
    In the first execution the report is showing correct units but in the same report when changes the fiscal year variable the units are showing wrong where GJ to J and TO to KG but these are not expected to do so.
    Even, we did cacche inactive for all BI reports by setting property 0 cache is inactive in RSRT.I chacked the reports with cache and with out cache but wrong units are being shown.
    Please advise me to overcome this issue at the earliest.
    Thanks,
    Pinky Reddy

    For this the solution is we need to do STO proces in reverse direction.
    i.e from receiving plant to supplying plant.
    So i am closing the issue.
    With Regards
    Azeez.Mohd

  • Variably Change a 2-D Array name

    Hi Everyone,
    So I have this VI that I had created and someone on here helped vamp it up big time. Thanks again for that. I have run into a snag with my program. So I have this VI that takes in arrays and places them in an xml file. I am using teststand to control a SigGen, PowerMeter, and a switch matrix so I can take a whole bunch of array measurements and place them into a singke xml file. My problem is that my xml file (when the test is completed) will have about 200 or more arrays in it. So I was hoping that I could make the 2-D array name into a variable so I can make each array unique in my xml file. That way I can eventually create another VI that takes the xml file and display the desired array. Does anyone know how to make the 2-D array name into a variable so I can change it to what I want from teststand? My VI is attached below.
    Thanks,
    dlovell
    Solved!
    Go to Solution.
    Attachments:
    Write to XML.vi ‏19 KB

    Hey Taki,
    So I understand now where you are coming from. Did your VI (the picture you posted) work? I can't get the 2D-Array to change to my Var_Name (my input name)... Below is my VI that I made look like your picture.
    Thanks,
    dlovell
    Attachments:
    Write to XML Test.vi ‏21 KB

  • Final Variable changed on runtime...

    Hello, I recently did a test with my program, which involved the use of 32 clients connecting to a server from a single application, however on runtime, the some final variables had their values changed, for example
    private static final Point point1 = new Point(100,100);
    had changed values to 480,360, and the default Point in my Point class had changed it's value from 0,0 to another value as well. How is this possible? The only methods used on the finalized point was equals/distance, which both do not affect the private fields of point, yet they were changed after logging in about 29 clients or so.
        public int distance(Point p2)
            return Math.max(Math.abs(p2.x - x), Math.abs(p2.y - y));
        public boolean equals(Point p)
            return (p.x == x && p.y == y);
        public boolean equals(Object obj)
            if (obj instanceof Point)
                return (((Point) obj).x == x && ((Point) obj).y == y);
            return false;
        }And here is where they are used
        private static final Point mine = new Point(167, 105);...
                        if (!cLoc.equals(mine))
                            if (cLoc.distance(mine) <= 18)
                                Player.jump(mine);
                                Player.Mine();
                                lastMineTime = 0;
                        }Any idea why this happened?

    Sorry, I was not clear enough
    Here is my Point class
    http://pastebin.com/m6075a9d8
    Now, after logging on about 38 clients (about 204 threads lol....), the constant fields get changed, for example within the point class, the "DEFAULT" gets changed to a random variable (which never happened before when logging on 10-20 only)
    Same goes for my other constant variables, their values get changed.
    For Example these Points:
        private static final Point sellPoint = new Point(417, 357);
        private static final Point mineExit = new Point(156, 90);
        private static final Point mineExitPoint = new Point(53, 399);
        private static final Point mineEntrance = new Point(45, 397);
        private static final Point mine = new Point(167, 105);Would get changed to something totally different, while the only functions used on those points are equals/distance.
    Here is an image of the Point instance while in debug mode:
    http://img193.imageshack.us/img193/6774/javaerror.jpg
    As you can see , mineExit takes the place of mineExitPoint (however I don't know why..), and mineExitPoint remains the same.....
    Another image:
    http://img6.imageshack.us/img6/9088/javaerror2.jpg
    Edit: Could it be the fact that around 30 threads are checking the same static/final variable at once?
    Edited by: Naki on Jul 1, 2009 6:43 PM

Maybe you are looking for

  • How do i burn idvd projects in a dvd format to an external hard disk

    I have an iDVD project but it is too big to burn to a dvd (11GB!) so I was wondering if I can save the proejct like a dvd onto my External Hard Disk. This is really urgent and important for a school project. Thanks in advance.

  • Error while querying a XML data type

    Hello Friends, I have a table which has a column type XMLTYPE In this table i store the XML documents.While retrieving data it works fine on my server. But when I query on another server it gives this error: SQL> select * from aw33_view;ERROR: ORA-04

  • MPN material check during PO

    Hi Gurus, We are procuring same material from two different vendors for two different plants  with same manufacturer. Internal material number is assigned with manufacturer part profile and manufacturer part no in the material master. I have created

  • ATV2 kicking other devices offline

    I've read threads about ATVs that disconnect themselves after sleep, but that's not my problem. I have a new ATV2 that effectively shuts down the internet for any other device on the network when it's in use, actually requiring a physical reboot of t

  • How to change New ShipTo Address functionality to Edit current ShipTo Addre

    Hi All, I have a requirement to change New ShipTo Address functionality to Edit current ShipTo Address.  Can someone please advise/direct me how to retrieve current ShipTo Address data and put it on New ShipTo page (Specify ShipTo page)? Any detail i