Accessing public variables

I have the code below. What I am trying to do is to print out
the value of a public variable. I am trying to change that public
variable in the function that handles the result of the remote
object call. The problem is the value only seems to change in the
function and no where else. Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="load_list()">
<mx:script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
public var material1_ID: int;
public function load_list():void{
material1_ID = 0;
public function addRec():void{
Alert.show('value before' + material1_ID.toString());
insertService.addMaterial('123'); // THis calls my webservice
and returns a query
Alert.show('value after' + material1_ID.toString());
public function addMaterial(event:ResultEvent):void{
material1_ID = 9;
]]>
</mx:Script>
<mx:RemoteObject
id ="insertService"
destination="ColdFusion"
source ="insert"
>
<mx:method name="addMaterial" result="addMaterial(event)"
>
</mx:RemoteObject>
</mx:Application>

This function in your code:
public function addRec():void{
Alert.show('value before' + material1_ID.toString());
insertService.addMaterial('123'); // THis calls my webservice
and returns a query
Alert.show('value after' + material1_ID.toString());
Looks to me like you are making the remote call and then
expecting the next line to access the result. Flex doesn't work
that way. Remote calls (including HTTPService and WebService) are
asynchronous. When you make the addMaterial call, the request goes
out and the response comes back "later". So right after that
request the value won't be changed.
If you print the value in the result handler, you'll see that
it will be changed.

Similar Messages

  • Accessing public variables from other classes

    Probably a simple questions, but how can I access a variable from another class. My exact situation is as follows.
    A class called WorldCalender has a variable which is defined: public int hour; (the value is given to it elsewhere).
    I want to access this variable and increase it by one in a subroutine in the class Hour. In this class I have put: WorldCalender.hour++; but it doesn't seem to work. How should I do it?

    don't expose the hour variable at all.
    have a method eg addToHourBy( int hrs )
    Probably a simple questions, but how can I access a
    variable from another class. My exact situation is as
    follows.
    A class called WorldCalender has a variable which is
    defined: public int hour; (the value is given to it
    elsewhere).
    I want to access this variable and increase it by one
    in a subroutine in the class Hour. In this class I
    have put: WorldCalender.hour++; but it doesn't seem to
    work. How should I do it?

  • Accessing a public variable between classes

    Hi there,
    I've got two classes running...one is a document class (EgoGame.as) and another is a class linked to several similar movie clips (Ball.as).
    I'm trying to access a public variable from Ball.as which has been declared in the doucment class EgoGame.as.
    When I run the test the outputs states the following...
    1120: Access of undefined property _ballPlaced.
    Here's my code.  What I'm trying to do is remove the event listeners from the Ball.as when the _ballPlaced variable is true, so that the user can't drag and drop the balls after they've been placed in a zone....any pointers greatly appreciated!
    Document Class
    EgoGame.as
    package
        import flash.display.MovieClip;
        import flash.display.DisplayObject;
        import flash.events.MouseEvent;
        import Ball;
        public class EgoGame extends MovieClip
            public var __zoneFull:Array = new Array(false, false, false);
            public var __ballPlaced:Array = new Array(false, false, false);
            public function EgoGame()
                ball0_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
                ball1_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
                ball2_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
                ball0_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
                ball2_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
                ball1_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
                ball0_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
                ball1_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
                ball2_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
            private function zoneEmpty(event:MouseEvent):void
                if(event.target.hitTestObject(zone0_mc) && _zoneFull[0] == true)
                    _zoneFull[0] = false;
                    _ballPlaced[event.target.name.substring(4,5)] = false;
                else if(event.target.hitTestObject(zone1_mc) && _zoneFull[1] == true)
                    _zoneFull[1] = false;
                    _ballPlaced[event.target.name.substring(4,5)] = false;
                else if(event.target.hitTestObject(zone2_mc) && _zoneFull[2] == true)
                    _zoneFull[2] = false;
                    _ballPlaced[event.target.name.substring(4,5)] = false;
                else
                    event.target.x = event.target._startX;
                    event.target.y = event.target._startY;
                    _ballPlaced[event.target.name.substring(4,5)] = false;
            private function zoneFill(event:MouseEvent):void
                if(event.target.hitTestObject(zone0_mc) && _zoneFull[0] == false)
                    event.target.x = zone0_mc.x;
                    event.target.y = zone0_mc.y;
                    _zoneFull[0] = true;
                    _ballPlaced[event.target.name.substring(4,5)] = true;
                else if(event.target.hitTestObject(zone1_mc) && _zoneFull[1] == false)
                    event.target.x = zone1_mc.x;
                    event.target.y = zone1_mc.y;
                    _zoneFull[1] = true;
                    _ballPlaced[event.target.name.substring(4,5)] = true;
                else if(event.target.hitTestObject(zone2_mc) && _zoneFull[2] == false)
                    event.target.x = zone2_mc.x;
                    event.target.y = zone2_mc.y;
                    _zoneFull[2] = true;
                    _ballPlaced[event.target.name.substring(4,5)] = true;
                else
                    event.target.x = event.target._startX;
                    event.target.y = event.target._startY;
                    _ballPlaced[event.target.name.substring(4,5)] =false;
            private function playMovie(event:MouseEvent):void
                if (_ballPlaced[0] == true)
                    ball0_mc.gotoAndPlay(2);
                else
                    ball0_mc.gotoAndStop(1);
                if (_ballPlaced[1] == true)
                    ball1_mc.gotoAndPlay(2);
                else
                    ball1_mc.gotoAndStop(1);
                if (_ballPlaced[2] == true)
                    ball2_mc.gotoAndPlay(2);
                else
                    ball2_mc.gotoAndStop(1);
    Ball.as
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.display.DisplayObject;
        import EgoGame;
        public class Ball extends MovieClip
            // public var _hitTarget:MovieClip;
            public var _startX:Number;
            public var _startY:Number;
            public function Ball()
                _startX = this.x;
                _startY = this.y;
                this.buttonMode = true;
                this.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
                this.addEventListener(MouseEvent.MOUSE_UP, dropIt);
            private function dragIt(event:MouseEvent):void
                this.startDrag();
            public function dropIt(event:MouseEvent):void
                this.stopDrag();
            public function lockBall(event:MouseEvent):void
                if(_ballPlaced[this.name.substring(4,5)] == true)
                    this.removeEventListener(MouseEvent.MOUSE_DOWN, dragIt);
                    this.removeEventListener(MouseEvent.MOUSE_UP, dropIt);

    every place you have a ball reference you can access the lockBall() method.  so, if ball0_mc is a Ball class member, you can use:
    ball0_mc.lockBall();

  • Why can't I access the variables in my threads?

    hello.
    another question about threads..
    ==========================
    I have an inner class that implements Runnable (i.e. a thread) and has a variable in it. I want to be able to access that variable from outside the thread class so that I can set or retrieve the variable.
    here is the code for the program
    class myClass
         public static void main(String[] args)
              myClass c = new myClass();
         myClass()
              Thread t = new Thread(new myThread());
              t.number = 1;
              t.start();
         class myThread implements Runnable
              int number = 0;
              public void run()
         }//end myThread
    }//end myClassthe line
    t.number = 1;
    where I try to set the number variable to 1 gives me an error (in the MyClass constructor)
    This is my error
    AccessThreadVars.java:11: cannot find symbol
    symbol  : variable number
    location: class java.lang.Thread
              t.number = 1;
                        ^
    1 errorif I put a method in myThread, and then try to call that method from myClass (via t.MethodName()) it gives me that same error telling me it can't find it..
    what am I doing wrong? how can I get access my thread's variables and methods??

    1. Type names should start with an uppercase letter
    2. t is defined as a Thread, not as a myThread
    (which, may I insist, should be "MyThread"), so the
    compiler has no means of detecting that "number" is
    an accessible field of the object... which wouldn't be accessible anyway, cause you're trying to get attributes from your Runnable after wrapping it inside a Thread.
    Why don't you do something like :
    MyThread t = new MyThread();
    t.number = 1;
    new Thread(myThread).start();?
    I bet you don't use Thread's own methods anyway...

  • How do I set a public variable in a native ActiveX DLL using Java?

    Hello,
    I have run into an issue that I cannot seem to find any documentation on, and all of my efforts with search engines have returned no useful results.
    Here is my situation:
    I have an Active X DLL that has a very simple configuration, but it is a third party DLL which I cannot modify. To interface with the DLL I have to set a series of public variables and then call a method with no parameters that will use the current values of the variables to perform a calculation. There are no "set" or "get" methods.
    At this point I have a very good idea about how to use JNI to create the class in java, and call the method. However, this does me no good at all if I cannot set the variables.
    Everything I have found so far defaults to an assumption of no direct access to variables, and that getter and setter methods would be available for that purpose. Anyone know of a way that this might be handled? I would provide source code, but it seems useless unless I know how to actually do this.
    Thanks in advance for any input.

    OK. Those are OLE/ActiveX/COM/WhateverTheyCallIt getters and setters, that VB makes look like object 'properties'.
    If you are familiar a bit with C#, they also have 'properties', which are getters and setters hidden behind a syntax that makes them look like member variables.
    I am affraid my help has to stop here, as I don't remember COM anymore.
    But, unless you find someone who really knows COM, you will have to investigate by yourself.
    One suggestion though: open a C++ project in VisualStudio 2005 or 2008 (not Express, it seems not to support what I describe).
    Go to something like References or Add Reference and you will see a tabbed dialog box with a COM tab (I describe all this from memory).
    Add your DLL. After this do View->Object Browser or alike. It should show your COM object. You will be able to examine its methods and properties.
    I think Visual Studio canl generate code for invoking them. This is the C code that somehow you should take from there and place in your JNI code.
    Edited by: baftos on May 9, 2010 11:22 AM
    Correction: VS2008 Express also supports this, but to get there, you do View->Object Browser->Click the "..." button->COM tab.
    VS2008 Express is free.
    Edited by: baftos on May 9, 2010 11:25 AM

  • Public variables in javascript

    how i can use public variables in javascript along with ADF. I am declaring a variable at the top of list but when an event is generated by ADF and i tries to access that variable, it gives me an error of undefined.
    Kindly help me

    Not directly, but you can with this:
    http://java.sun.com/products/plugin/1.3/docs/jsobject.html
    See also:
    http://www.codeproject.com/jscript/javatojs.asp?df=100&forumid=736&exp=0&select=700857

  • Access session variable in Java Function in JSP

    Hi Experts !!
    I am developing an application using STRUTS MVC...
    Very sorry if u have problem understanding my question, i ll try to improve... and sorry if i can't post codes here
    Basic question is ....
    I want to open a word document on pageLoad of JSP, the word document is not a single document, there is a form in which there is a "name" and "template" whenever user clicks on a button there is one action attached to it which creates a copy of that template in a different folder.. on the next page OnLoad i want to open that particular document. for that i have created a variable and also have set in the session, just want to access it in the below code.
    I have a formbean in which i have a variable, the scope is session, that variable i have put it in session also. but i want to access that variable in a "java function" in JSP so that "onLoad" page that function should work.
    JSP---
    <script type="text/javascript">
    function openDocument() {
    var w = new ActiveXObject("Word.Application");
    var docText;
    var obj;
    var a;
    if (w != null) {
    w.Visible = true;
    obj = w.Documents.Open(I HAVE TO ACCESS THAT VARIABLE HERE);
    </script>
    FORMBEAN----
    public class CreateSOWFormBean extends ActionForm {
    private String workflowName;
    private String comment;
    private String sowTemplate;
    private String sowFileCreated;
    public String getSowFileCreated() {
    return sowFileCreated;
    public void setSowFileCreated(String sowFileCreated) {
    this.sowFileCreated = sowFileCreated;
    sowFileCreated is the variable that i have accessed in session and that value i have to pass in that function in JSP....
    I am aware of something like
    obj = w.Documents.Open(<%'sowFileCreated'%>);
    but i m not sure how to write....
    Plz help.....

    If you're working under a framework like struts you should definitely be using JSTL tags rather than scriptlet code to access variables within the page. With JSTL code <% codes can be almost entirely avoided.
    To transfer a value from a Servlet to a JSP don't use a session variable, use a request attribute. Session variables should only be used when values have to survive from one transaction to another.
    You can write something like:
    obj = w.Documents.open('<c:out value="${openURL}"/>');in the Javascript portion of your JSP.
    Just beware of potential problems with quotes. The coresponding code in the Servlet would be like:
    request.setAttribute("openURL", openUrl);

  • How to access (call) variables from multiple components

    I have what I think is a basic task, but I cant seem to get it to work.  I have a Flex project with one application.  In addition to the one application, I have many components that are used in the application.  These components vary from simple (a ComboBox) to complex (many sub-components).  What I need to do is define a viable in one component and access it in another component.  I can't seem to do this.  Below is an example of how I think it should be:
    Component1
    <mx:Script>
           <![CDATA[
            [Bindable]
            private var userID:int=0;
           ]]>
    </mx:Script>
    Component2
    <mx:TextInput  text="{Component1.userID}"/>
    Any help you can provide would be beneficial.
    Lee

    Hello,
         You may also want to consider using the mx.core method.
         In your main application script area define all of your public variables and functions. Then from your component, you can reference these absolutely with the following syntax.
    <!-- Main App -->
    [Bindable]
    public var userID:int;
    <!-- Component -->
    private function init():void {
         var com_UserID = mx.core.Application.application.userID;
    Using this method ensures that you will have access to any Function or variable within the scope of the project.
    Kind Regards,
    Dr. Ivan Alexander, Ph.D.
    Sr. Applications Engineer
    FlexAppsStore.com
    Sun Microsystems
    MySQL Enterprise Ready Partner 2009

  • Custom taglib access the variable of jsp in the tag class

    Hi guys:
    I have a question about taglib.the scenario below
    there are a set of tag,they all need to access a variable that declare in the jsp.yes ,I can use the approach like this,
    first I declare a variable
    <%!String variable="test";%>
    then pass the value
    <myTag:hello att="<%=variable%>"/>,but I think that's stupid,because all tags access the same variable.why not get the variable in tag class?
    for example
    public int doStartTag() {
    String variable=;//get the variable at here
    I mean,I want to get the variable's value in my tag class directly without passing parameter in the jsp via attribute of tag ?
    can I do like this?if yes,how can I?
    thanks advance!

    Hi,
    Review pageContext, TagSupport from the JSP and Tag Extensions API. You can put the variable into any of the four scopes and retrieve it using the pageContext object.

  • Accessing a variable declared in another form

    Can someone tell me how I access a variable outside from the form it was declared in? I've tried examples but they haven't worked.

    There are many right ways and many wrong ways to do what you want, the two below (one code example) and one link to a demo project are but two ways to do this.
    A simple example, form1 as two buttons, form2, two buttons, one text box. This replies on knowing the parent form.
    Public Class Form1
    Public SomeVar As String = "Karen"
    Public Property SomeProp As Integer = 4
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim f As New Form2 With {.Owner = Me}
    Try
    f.ShowDialog()
    Finally
    f.Dispose()
    End Try
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    MessageBox.Show(Me.SomeVar)
    End Sub
    End Class
    Form2
    Public Class Form2
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim MyParent As Form1 = CType(Me.Owner, Form1)
    MessageBox.Show(MyParent.SomeProp.ToString & Environment.NewLine & MyParent.SomeVar)
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim MyParent As Form1 = CType(Me.Owner, Form1)
    MyParent.SomeVar = Me.TextBox1.Text
    End Sub
    End Class
    The following link has a project which is much more involved, I allow non-modal forms to pass data between the two in real time and both forms stick to each other.
    https://onedrive.live.com/redir?resid=a3d5a9a9a28080d1!727&authkey=!AEQ4n6P1H4sD6QI&ithint=file%2czip
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

  • Accessing session variables with php

    I am trying to access the  session variable  $_SESSION['MM_Username']  in one of my php pages, but it is somehow showing empty (i.e it does not contain the username that was entered during login).
    I checked and confirmed that my login.php function is properly setting the MM_Username session variable by echoing it  from the login function.
    So why can't I read it from another php file in the same session?  Do I need to do something else before the session variables can
    be properly read from any php file in the same session?  Any help would be appreciated.

    Here is a test code I am using to access the session variable $_SESSION['MM_username']  from  the php page  test.php. But it is not working.
    I get an empty string all the time for $username. Can any one see something wrong with this code?
    <?php require_once('Connections/MyTestingConn.php'); ?>
    <?php session_start(); ?>
    <?php
    $username = "-1";
    if (isset($_SESSION['MM_username'])) {
      $username = $_SESSION['MM_username'];
      echo $username;
    else
       echo "Eror: can not access session variable";
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    </head>
    <body>
    </body>
    </html>

  • Public variables can be shared by multiple users?

    I have public static variables in some of my classes...think that there are 2 pages...
    page1:sets that public variable..
    page2:reads that public variable...
    so the 2. person can read 1. person's variable by directly calling the second page or he gets null,error etc:?
    its important for the security!generally are the values are session protected?or user must handle this security by coding correctly...
    thank you

    Actually, neither your question nor your English are
    particularly clear.
    However, if you're asking what I think you're asking,
    then, yes, the variable can be seen by multiple
    "users." I put that in quotes because there really
    isn't a concept of "users" or "people" here unless
    you build in such a layer. It's really requests that
    we're talking about.
    Servlets should not usually have member variables.
    The reason is that usually only one instance of your
    Servlet implementation exists, and it processes all
    requests for that servlet. This is more a data
    validity issue than a security one. Security comes in
    at the layer where you build it (or use a 3rd party
    library), but a side effect of this can be compromisd
    security. The access levels--public, private, etc.
    are NOT intended for security purposes, however.
    Now, if that servlet's doGet(), doPost(), service(),
    or whater methods create instances of some
    other class, then, no, other requests cannot
    see those objects, as long as the references to them
    stay local to the servlet's methods, and don't get
    put into the servlets member variables or an
    application context.thank you this is what i exactly wanted to learn...i have also tested it with my test codes and same things seen parallel to your explanations...

  • Accessing a variable form a super class

    Hi guys, its my first post in this forum, i am student and learning some java. I find it very interesting but have some problems
    My question is : How to access a variable from a superclass
    Here is my program:
    class superclass
         int i = 10, j= 20;
         void display()
         System.out.println("i in super is:" +i);
         System.out.println("j in super is:" +j);
    class child extends superclass
         int i,j;
         void display()
         System.out.println("i in child is:" +i);
         System.out.println("j in child is:" +j);
    class prgdemo
         public static void main(String args[])
         superclass s =new superclass();
         s.display();
         child c = new child();
         c.display();
    }Thanks for your replies

    This is only true of nested subclasses. Private
    fields are HIDDEN to ALL code contained outside of
    the enclosing class.You are a very bad racist man:class superclass {
         private int i = 10;
         private int j= 20;
         public class child extends superclass
              int i= 42,j= 54;
              void display()
              System.out.println("i in child is:" +i);
              System.out.println("j in child is:" +j);
              System.out.println("super's i is:" +super.i);
              System.out.println("super's j is:" + super.j);
              System.out.println("outer's i is:" + superclass.this.i);
              System.out.println("outer's j is:" + superclass.this.j);
         void display()
         System.out.println("i in super is:" +i);
         System.out.println("j in super is:" +j);
    }kind regards,
    Jos (eeeww!)

  • Accessing private variables

    I'm a little confused. I know that using private instance variables is good practice, and that the appropriate way to access those variables is with accesser methods (getXXX(), etc.). Since the variables are private, you can't access them by just referring to "testClass.variable", right?
    Well, I was reading up on the Comparable interface today, and found a code example where a class implemented a compareTo() method like this:
    public int compareTo(Object o) {
       if (privateVariable < (TestClass) o.privateVariable) {
          return -1;
       } else {
          return 1;
    }But privateVariable is declared as a private variable. So why is it that you can refer to o.privateVariable in the compareTo() method? Is it just because o is cast as a TestClass object, and the compareTo() method is inside of the TestClass class? Even if that's the case, it still seems weird to me; if privateVariable is declared private, I'd think that any reference to a TestClass.privateVariable variable would throw an exception, even if the reference is within the TestClass. This just seems different to me than referring to the privateVariable variable within TestClass, because that obviously refers to the member of the current instance, not a different instance.
    Anyway, any explanation would be appreciated.
    Rich

    Yes, 'private' means 'private to this class', not 'private to this object'.
    In this way, it behaves somewhat like a 'friend' variable. The basic idea of making variables private is to hide the implementation behind a class, which still holds even with the compareTo method (you can't use it to figure out that there's a variable called 'privateVariable', when using it from outside your class.)

  • Accessing _root variable from flex

    In Flex code, I am trying to access a variable that I pass to
    the Flash object through FlashVars argument. In Flash it is easy to
    do as all the variables that as passed as a part of FlashVars
    appear as a part of _level0 or _root. Is there any way to do it in
    Flex?
    I am trying pass a large dataset directly to Flash without an
    http call (creating a desktop application). Does anyone know if the
    FlashVars approach will work for a large dataset or is there a
    better approach?
    Thanks

    From the Flex 2.0.1 help (search for Using flashVars):
    The following example sets the values of the firstname,
    middlename, and lastname flashVars properties inside the
    <object> tag in a simple wrapper:
    <?xml version="1.0"?>
    <!-- wrapper/ApplicationParameters.mxml -->
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="initVars()">
    <mx:Script><![CDATA[
    // Declare bindable properties in Application scope.
    [Bindable]
    public var myName:String;
    [Bindable]
    public var myHometown:String;
    // Assign values to new properties.
    private function initVars():void {
    myName = Application.application.parameters.myName;
    myHometown = Application.application.parameters.myHometown;
    ]]></mx:Script>
    <mx:VBox>
    <mx:HBox>
    <mx:Label text="Name: "/>
    <mx:Label text="{myName}" fontWeight="bold"/>
    </mx:HBox>
    <mx:HBox>
    <mx:Label text="Hometown: "/>
    <mx:Label text="{myHometown}" fontWeight="bold"/>
    </mx:HBox>
    </mx:VBox>
    </mx:Application>
    If you are using the wrapper that is generated by Flex Data
    Services or wrappers that are included in the
    resources/html-templates directory, your wrapper might not look the
    same, but the basic approach to passing the flashVars variable is.
    For example, you might insert flashVars variables by appending them
    to a function parameter, as the following example shows:
    "flashvars","historyUrl=%2Fflex%2Fflex%2Dinternal%3Faction%3Dhistory%5Fhtml&lconid="
    + lc_id + "&firstName=Nick&lastName=Danger",

Maybe you are looking for