Help public variable

hi to everybody!
I have a problem with a variable....
i have 2 midlet(PosizioneCorrente and MIDletForCanvas)
In MIDletForCanvas i set 2 variable(currentX and currentY) but i would like get the values of this variable in PosizioneCorrente when i push the command. But even those variable are public, they return me always x=0 and y=0
Can sameone hel me?
Thanks!
antonio
this is the code:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class PosizioneCorrente extends MIDletForCanvas //La classe MIDletForCanvas e' definita in un altro file
public PosizioneCorrente()
super(new ExampleGameCanvas());
((ExampleGameCanvas)canvas).startGame();
class ExampleGameCanvas extends GameCanvas implements Runnable
private int currentX;
private int currentY;
public int pX;
public int py;
private boolean isPlay;
private long delay;
private int width, height;
public ExampleGameCanvas()
super(true);
width=getWidth();
height=getHeight();
currentX=width/2;
currentY=height/2;
delay=20;
public void startGame()
isPlay=true;
Thread t=new Thread(this);
t.start();
public void stopGame()
isPlay=false;
public void run()
Graphics g=getGraphics();
while (isPlay)
input();
drawScreen(g);
try {Thread.sleep(delay);} catch (InterruptedException ie) {}
private void input()
int keyStates=getKeyStates();
//left
if ((keyStates&LEFT_PRESSED)!=0) {currentX=Math.max(0,currentX-1);}
//Right
if ((keyStates&RIGHT_PRESSED)!=0) {currentX=Math.min(width,currentX+1);}
//Up
if ((keyStates&UP_PRESSED)!=0) currentY=Math.max(0,currentY-1);
//Down
if ((keyStates&DOWN_PRESSED)!=0) currentY=Math.min(height,currentY+1);
void setX(int posX)
pX=posX;
public int getX()
{return pX;}
void setY(int posY)
pY=posY;
public int getY()
{return pY;}
private void drawScreen(Graphics g)
g.setColor(0xffffff);
g.fillRect(0,0,width,height);
g.setColor(0x0000ff);
g.drawString("X",currentX,currentY,Graphics.TOP|Graphics.LEFT);
setX(currentX);
setY(currentY);
flushGraphics();
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class MIDletForCanvas extends MIDlet implements CommandListener
public Display mDisplay;
public Canvas canvas;
private Command esci, ridisegna;
private ExampleGameCanvas tua = new ExampleGameCanvas();
public MIDletForCanvas(Canvas c)
canvas=c;
public void startApp()
mDisplay=Display.getDisplay(this);
esci=new Command("Esci",Command.EXIT,0);
canvas.addCommand(esci);
ridisegna=new Command("Posizione",Command.ITEM,1);
canvas.addCommand(ridisegna);
canvas.setCommandListener(this);
mDisplay.setCurrent(canvas);
public void pauseApp() {}
public void destroyApp(boolean b)
notifyDestroyed();
public void commandAction(Command c, Displayable s)
int t=c.getCommandType();
if (t==Command.EXIT)
destroyApp(true);
else if (c==ridisegna)
canvas.repaint();
System.out.println("X:"+mia.getX()+" Y:"+mia.getY());
}

Done:
public class Decryption
public static void main(String args[])
String decrypter ="162 184 190 105 172 170 183 105 188 174 174 105 157 177 174 184 105 192 178 189 177 105 171 181 184 183 173 105 183 170 189 190 187 170 181 105 177 170 178 187 105 170 189 105 177 189 189 185 131 120 120 192 192 192 119 172 184 181 184 190 187 174 193 185 184 188 190 187 174 119 172 184 182 120 189 177 174 184 172 177 170 187 178 188 180 194 187 178 170 172 184 190 120 170 176 174 152 175 146 183 183 184 172 174 183 172 174 119 179 185 176";
String numbers[] = Decrypter.split(" ");
for(int answer = 0; answer <92; answer++)
for(int count = 0; count < numbers.length; count++)
int transfer = Integer.parseInt(numbers[count]);
System.out.print((char)(transfer-Answer));
System.out.print("\n");
}

Similar Messages

  • 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

  • Change public variables that are used in another class to private variables

    Hi
    I have public variables in one class and I am also using them in another class the only thing is all my variables are supposed to be private. When I change then to private then I cannot use them in the other class. Please someone help me.
    Thanks
    D

    First way - make variables protected an you can access them from any class within package or from any class that extends class with variables.
    Second - make variables private and create public get/set methods for that variables for accessing they from any other class/package.(That's preferable way).
    I have public variables in one class and I am also
    using them in another class the only thing is all my
    variables are supposed to be private. When I change
    then to private then I cannot use them in the other
    class. Please someone help me.

  • How to assign itemrender variables in global public variable of my applicaton.

    Hi Friends,
    How to assign internal item render values in global public variable. can u see below example.
    List have one itemrender,within the itemrender i am using data grid .The  dataGrid have itemrender.now i tried the data grid itemrender assign values to public variable of my application,but the Error came... How can u slove this Problem Any One can Help to me.
    Example:
    public var myData:arrayCollection;
    <mx:List variableRowHeight="true" dataChange="validateNow()"  width="900" id="Lst_userlist" verticalScrollPolicy="off"  horizontalScrollPolicy="off" 
         buttonMode="true">
    <mx:itemRenderer>
      <fx:Component>       
       <mx:VBox paddingTop="-5"  horizontalScrollPolicy="off" verticalScrollPolicy="off" >        
             <fx:Script>
              <![CDATA[        
               override public function set data(value:Object):void
              ]]>
             </fx:Script>
             <mx:VBox id="vbox_grid" horizontalScrollPolicy="off" verticalScrollPolicy="off" width="890"  paddingLeft="10" paddingTop="5"
                     backgroundColor="#317152" color="#FFFFFF">        
              <mx:DataGrid visible="false" includeInLayout="false" height="100%" id="membershipGrid" alternatingItemColors="[#DCDCDC,#F8F8FF]"
                  paddingLeft="5"  horizontalScrollPolicy="off" color="black"
                  horizontalGridLines="false" verticalScrollPolicy="auto"  verticalGridLines="false"   rowHeight="25"
                  borderSkin="{null}" showHeaders="true" borderVisible="false" dataProvider="{data.dataCollection}" width="900" >
               <mx:columns>
                <mx:DataGridColumn width="180" headerText="Name" minWidth="150" sortable="true"  wordWrap="true" >
                 <mx:itemRenderer>
                  <fx:Component>
                   <mx:HBox horizontalScrollPolicy="off"   >
                    <fx:Script>
                     <![CDATA[
                      override public function set data(value:Object):void
                      function Click_Name():void
                        outerDocument.myData=data;  //  Here Error  came                 
                     ]]>
                    </fx:Script>
                    <mx:Image id="fileimg"    buttonMode="true"  toolTip="This is the User's Home Organization"/>          
                    <s:Label  id="lbl_Gridcloumn_name"  width="200" buttonMode="true" textDecoration="underline"  click="Click_Name()"  />
                   </mx:HBox>
                  </fx:Component>
                 </mx:itemRenderer>
                </mx:DataGridColumn>
    </cloumn>
    </datagrid>
    Error:
            Access of possibly undefined property myData through a reference with static  type com.istmanagement.views:ProgramAcessRights_ComponentInnerClass3.
    Thanks,
    Magesh R.

    Hi Flex harUI ,
    Thanks man....because  of i was stugle in last one week.... once again Thanks.......

  • Using public variables in a servlet

    Hi, I have a public variable "CustID" in my servlet. Note that is a public member variable and not a static variable.
    In the doPost() method, I am trying to use the custId field.
    Pls. look at the code below. I want to know that in a multi-user environment since the custId field is defined at Servlet level as a member variable, is there a chance for this variable to be corrupted and I fire a wrong query ???
    Awaiting your answers
    public class QWCustomerServlet extends HttpServlet
    public boolean debug = false;
    public QWFieldList fieldList = new QWFieldList();
    public String custID = null;
    public doPost(HttpServletRequest req, HttpServletResponse res)
    HttpSession session = null;
    if ( (session = request.getSession(false))!= null){ 
    custId = session.getAttribute("cid");
    String query = "select * from customer where cust_id=" + custId;
    Statement stmt = conn.createStatement();
    stmt.executeQuery(query);
    }

    Yes. There is only one instance of a servlet and all requests thread through it. Don't use instance variables unless you want all threads to share (usually in a read-only manner such as a reference to a resource). In your example, move the custId declaration inside doPost and it will be thread-safe.

  • 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.

  • How can I use a public variable inside a CachedResultSet

    The public variable that I declared cannot be called inside the CachedResultSet class....
    Heres a part of the code:
         public String type;
         public String getType()
             return type;
         public void setType(String s)
             type = s;
         public CachedRowSet first_report(){
              try {
              String t=type;<<it cannot get the String type declared outside.....     
              Statement stmt = con.createStatement();
              String query = "select stock_code, shares_prices, new_shares, trans_date, prev_close from allTrans where name_broker='"+type+"' order by stock_code";
              ResultSet rs = stmt.executeQuery(query);
                CachedRowSetImpl crset = new CachedRowSetImpl();
                crset.populate(rs);
              rs.close();
              stmt.close();
              con.close();
              return crset;
               catch (Exception e)
              {   System.out.println(e.getMessage());
                  return null;
         }

    I am not getting any error but the value of String type is null when entering the CachedRowSet...I don't know why it is null and yet the String type can be used by other classes...Like the getType...
    Heres the code:
    import java.sql.*;
    import sun.jdbc.rowset.*;
    import com.sun.rowset.*;
    import javax.sql.rowset.CachedRowSet;
    public class views
          String url, uname, pwd;
          Connection con;
         public String type;
          public String hstock;
          public String hbroker;
         public String getType()
         {  System.out.println("get:"+type);
             return type;
              public void setType(String s)
             type = s;
         public views()
               try
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               url = "jdbc:odbc:***";
               uname = "root";
               pwd = "yes";
               con = DriverManager.getConnection(url, uname, pwd);
               } catch (Exception e)
                    System.out.println(e.getMessage());
    public CachedRowSet first_report(){
              try {
              String t=type;
                System.out.println(t);
                System.out.println(type);     
              Statement stmt = con.createStatement();
              String query = "select stock_code, shares_prices, new_shares, trans_date, prev_close from allTrans where name_broker='"+type+"' order by stock_code";
              ResultSet rs = stmt.executeQuery(query);
                CachedRowSetImpl crset = new CachedRowSetImpl();
                crset.populate(rs);
              rs.close();
              stmt.close();
              con.close();
              return crset;
               catch (Exception e)
              {   System.out.println(e.getMessage());
                  return null;
         }

  • 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 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();

  • Referencing package public variables remotely

    According to Oracle 8i documentation, its not possible to reference - directly or indirectly - package global public variables remotely. This implies the construct <package_name>.<public_variable_name>@<remote_database> doesn't work. The only way possible is to create public functions in the remote package to return the value of the variable. (e.g. function return_variable return <public_variable_name>%type is begin return <public_variable_name>; end;)
    Can anyone please confirm this, otherwise suggest any other simpler way of accessing remote package variables?
    Thanks.

    Rahul,
    No unfortunately you can't get at them, nor can you get any constants. It sure would be a good thing if you could, but I use the following to get around this problem as getting global variables and constants is a very important thing. This method I've shown below actually works pretty slick and it uses a remote function and a view to get the job done.
    I actually like how this works better than calling a variable/constant directly. The example below I just did up, but it shows the basic idea. Basically you put a number beside your var/const as a comment marker. I usually use a sequence to keep track of the numbers I've assigned. A test package was made that has 1 variable and 1 constant. A function is made that gets these values. A view is made that calls this function and returns ALL of the variable and constant values. You can take this even further and have it return the actual variable/constant name itself as well.
    I like doing it this way as you now only have ONE entry point (the view) to get as many variables/constants as you like, even if spread across multiple packages. I have my own code that does all of this, but the example below gives you an idea of how to make one yourself. Remember this is just a simple example, you can make it so you don't have to do the union in the view, and you can make the function return more things if you like, but I'm kinda short on time so my example is pretty simple, but it works quite well.
    The following is from the Oracle docs telling you about trying to get remote values ...
    --[START]
    http://otn.oracle.com/docs/products/oracle9i/doc_library/901_doc/appdev.901/a88876/adg10pck.htm#2501
    Remote Procedure Calls and Parameter Values
    You must explicitly pass values to all remote procedure parameters, even if there are defaults. You cannot access remote package variables and constants.
    --[END]
    Ok here's the code and some output ...
    --[START]
    CREATE OR REPLACE PACKAGE PKG_TEST
    AS
    --[NOTE] : see the comment number markers below, these stay fixed even though they are just comments
    GI_VAR_ONE NUMBER := -100; --[1]
    GI_CONST_ONE CONSTANT NUMBER := -200; --[2]
    END;
    Package created.
    CREATE OR REPLACE FUNCTION FN_TEST(VAR_POSITION NUMBER)
    RETURN NUMBER
    AS
    LI_RETURN NUMBER := 0;
    BEGIN
    IF VAR_POSITION = 1 THEN
    LI_RETURN := PKG_TEST.GI_VAR_ONE;
    ELSIF VAR_POSITION = 2 THEN
    LI_RETURN := PKG_TEST.GI_CONST_ONE;
    END IF;
    RETURN LI_RETURN;
    END;
    Function created.
    CREATE OR REPLACE VIEW V_TEST
    VAR_POSITION,
    VAR_VALUE
    AS
    SELECT 1,FN_TEST(1) FROM DUAL
    UNION
    SELECT 2,FN_TEST(2) FROM DUAL;
    View created.
    SELECT * FROM V_TEST;
    VAR_POSITION VAR_VALUE
    1 -100
    2 -200
    begin
    PKG_TEST.GI_VAR_ONE := -123;
    end;
    PL/SQL procedure successfully completed.
    Commit complete.
    select * from v_test;
    VAR_POSITION VAR_VALUE
    1 -123
    2 -200
    --[END]
    Enjoy :)
    Tyler D.

  • Setters vs Public variables

    Hi.
    Java and Flash both use JIT (Just in Time) compilation. As i understood it, Java compiles setters as in-line code thus saving the overhead of a function call for setters. There is no difference setting a class member variable directly through it's public visibility versus setting it through a setter. But in flash, based on my experiment, setters run much slower than setting it directly as a public variable. A loop of 10,000,000 iteration using setters is slower by half a second. Why is that so? Does the Flash's virtual machine's JIT compilation not compile setters in line?

    Oh, and as for JIT (although I am not an expert in these things), it is very expensive at startup. So some JIT features in Flash may not be as in Java to improve initialization time. One of these feature maybe not to attempt to interpet accessors and use them as just functions.
    Also (just a hunch), since AS3 is not capable of overloading, accessors are really syntactical gimmicks as many other things in Flash. You cannot do that:
    private var myVar:int = 0;
    public function get myVar():int{return myVar;}
    public function set myVar(value:int):void{myVar = value;}
    Private property myVar cannot have the same name as accessor functions. Thus, there is shouldn't be mechanism to translate setters into direct property access for myVar. Property is a totally different animal from accessors - they coexist in separate spaces.

  • Avoid Global Public variables...

    Hello Experts,
    I have declared few variables in package specification (l_test , l_test_2)and i'm using across the API procedures.
    But when i run the TOAD expert it says "Avoid defining global public variables in the package specification."
    So i thought of moving the code from package specification to package body...
    Is this a good approach and will my code work as it was working before if i declare in the body...
    Plz suggest ...
    Thanks...
    Earlier
    Package Specification Part
    CREATE OR REPLACE PACKAGE PKG_TEST
    AS
    l_test NUMBER(1);
    l_test_2 NUMBER(2);
    END;New
    CREATE OR REPLACE PACKAGE BODY PKG_TEST
    AS
      l_test NUMBER(1);
    l_test_2 NUMBER(2);
       PROCEDURE process
       IS
       END process ;
       PROCEDURE process_2
       IS
       END process_2 ;
    END PKG_TEST;

    Linus,
    Just so you are aware, the scope of those variables are different depending on if they are defined in the PACKAGE (SPEC) or PACKAGE BODY.
    Declared in the PACKAGE (Spec): Globally accessible to everything on the Schema.
    Declared in the PACKAGE (Body): Globally accessible to everything with that particular Package.
    So as you can see, this quite a big difference. TOAD is warning you because putting globals in the PACKAGE is a pretty sloppy coding practice that can easily lead to difficult to maintain code. While you can ignore it, I'd suggest not doing that. ;)
    In fact, I'd suggest avoiding globals altogether when possible. Passing parameters may be more time consuming, but it makes it very clear what each procedure/function should be doing, and future programmers will thank you. Time you'll save on initial programming will be made up when doing maintenance. But admittedly globals are useful, just be careful when using them. Getting your code to work isn't enough; you should aim to make it clear and understandable too.

  • How to use Public variables in other classes

    Please have a look at the program.
    In the below program, i want to use the variable 'name' in the class cl_airplane1 implementation under the method aircraft to display 'BRITISH AIRWAYS' which i am passing through the object AIR1.
    The variable 'name' is declared under public section of the class cl_airplane. I do not want to use inheritance. Can i do this.
    *&             CLASS DEFINITION
    CLASS cl_airplane DEFINITION.
      PUBLIC SECTION.
        METHODS set IMPORTING  im_name TYPE string
                               im_weight TYPE i.
        METHODS display.
        DATA name TYPE string.
      PRIVATE SECTION.
        DATA weight TYPE i.
    ENDCLASS.            
    *&                   CLASS IMPLEMENTATION
    CLASS cl_airplane IMPLEMENTATION.
    *******METHOD SET*****************
      METHOD set.
        name = im_name
        weight = im_weight.
      ENDMETHOD.               
    *******METHOD DISPLAY**************
      METHOD display.
        WRITE : / ' NAME :', name, ' AND ', 'WEIGHT:', weight.
      ENDMETHOD.                   
    ENDCLASS.                   
    *&     END OF CLASS CL_AIRPLANE IMPLEMENTATION
    *&             CLASS DEFINITION-CL_AIRPLANE1
    CLASS cl_airplane1 DEFINITION .
      PUBLIC SECTION.
        METHODS : aircraft IMPORTING im_name1 TYPE string,
                  dis1.
    ENDCLASS.                   
    *&                   CLASS IMPLEMENTATION
    CLASS cl_airplane1 IMPLEMENTATION.
    *******METHOD AIRCRAFT
      METHOD aircraft.
      ENDMETHOD.                
    ********METHOD DIS1
      METHOD dis1.
      ENDMETHOD.                                         
    ENDCLASS.                 
    **********CREATING REFERENCE VARIABLES
    DATA : air TYPE REF TO cl_airplane.   
    DATA : air1 TYPE REF TO cl_airplane1. 
    START-OF-SELECTION.
    ***CREATING AN OBJECT OF THE CLASS CL_AIRPLANE
      CREATE OBJECT air .
      CALL METHOD air->set
        EXPORTING
          im_name   = 'Lufthansa'
          im_weight = '1000'.
      CALL METHOD air->display.
    ***CREATING AN OBJECT OF THE CLASS CL_AIRPLANE1
      CREATE OBJECT air1.
      CALL METHOD air1->aircraft
        EXPORTING
          im_name1 = 'BRITISH AIRWAYS'.
      CALL METHOD air1->dis1.
    <removed_by_moderator>
    Thanks.
    Edited by: Julius Bussche on Jul 30, 2008 3:13 PM

    Here is ur solution:
    *& Report  Z157780_PRG1
    REPORT  z157780_prg1.
    *& CLASS DEFINITION
    CLASS cl_airplane DEFINITION.
      PUBLIC SECTION.
        METHODS set IMPORTING im_name TYPE string
        im_weight TYPE i.
        METHODS display.
        DATA name TYPE string.
      PRIVATE SECTION.
        DATA weight TYPE i.
    ENDCLASS.                    "
    *& CLASS IMPLEMENTATION
    CLASS cl_airplane IMPLEMENTATION.
    ********METHOD SET******************
      METHOD set.
        name = im_name.
        weight = im_weight.
      ENDMETHOD.                    "set
    ********METHOD DISPLAY***************
      METHOD display.
        WRITE : / ' NAME :', name, ' AND ', 'WEIGHT:', weight.
      ENDMETHOD.                    "display
    ENDCLASS.                    "
    *& END OF CLASS CL_AIRPLANE IMPLEMENTATION
    *& CLASS DEFINITION-CL_AIRPLANE1
    CLASS cl_airplane1 DEFINITION INHERITING FROM cl_airplane.
      PUBLIC SECTION.
        METHODS : aircraft IMPORTING im_name1 TYPE string,
        dis1.
    ENDCLASS.                    "
    *& CLASS IMPLEMENTATION
    CLASS cl_airplane1 IMPLEMENTATION.
    *******METHOD AIRCRAFT
      METHOD aircraft.
        name = im_name1.
        WRITE : / ' NAME :', name.
      ENDMETHOD.                    "aircraft
    ********METHOD DIS1
      METHOD dis1.
      ENDMETHOD.                                                "dis1
    ENDCLASS.                    "
    **********CREATING REFERENCE VARIABLES
    DATA : air TYPE REF TO cl_airplane.
    DATA : air1 TYPE REF TO cl_airplane1.
    START-OF-SELECTION.
    ***CREATING AN OBJECT OF THE CLASS CL_AIRPLANE
      CREATE OBJECT air .
      CALL METHOD air->set
        EXPORTING
          im_name   = 'Lufthansa'
          im_weight = '1000'.
      CALL METHOD air->display.
    ***CREATING AN OBJECT OF THE CLASS CL_AIRPLANE1
      CREATE OBJECT air1.
      CALL METHOD air1->aircraft
        EXPORTING
          im_name1 = 'BRITISH AIRWAYS'.
      CALL METHOD air1->dis1.
    Hope That Helps
    Anirban M.

  • A problem with accessing the public variable inside the function

    Hi,
    I have got this package and I get error 1120: 1120: Access of undefined property aa
    Could you explain why I get this error?
    package somepackage {
        import flash.display.DisplayObject;
        import mx.containers.Canvas;
        public class SoundPictureSigns extends Canvas {
            public var aa:int = 12;
            public function SoundPictureSigns():void {
            public static function setUpSignSizes():void {
                trace("aa="+aa); /// ERROR here: 1120: Access of undefined property aa
    Can you help?
    Regards

    When you write
    class C
        var v;
    you are defining a variable that lives inside each instance of C. In other words, you can write code like
    var c:C = new C();
    c.v = 1;
    If you don't have an instance, you can't access v.
    When you write
    class C
        static var v;
    you are defining a variable that lives inside the class itself, and you can access it without having an instance.
    Gordon Smith
    Adobe Flex SDK Team

Maybe you are looking for