Pass variable name to class that modifies it

in my main fla:
import Preloader;
var prel:Preloader = new Preloader();
var toPass=9;
prel.loads(this,stage,"toPass",2);
in my Preloader.as:
package  {
          import flash.display.Sprite;
          import flash.display.Stage;
          import flash.events.Event;
     public class Preloader extends Sprite {
          private var stageRef:Stage;
          private var mainTimeLineRef:*;
          public function loads(a,b,c,d):void{
               this[c]=d
I want to pass the toPass var to my class that has to edit that, how can i do?  (i know that i could simply write toPass = d)

i'm not sure what you're trying to do but to pass a variable's value, use:
framode wrote:
in my main fla:
import Preloader;
var prel:Preloader = new Preloader();
var toPass:int=9;
prel.loads(stage,toPass);
in my Preloader.as:
package  {
          import flash.display.Sprite;
          import flash.display.Stage;
          import flash.events.Event;
     public class Preloader extends Sprite {
          private var stageRef:Stage;
          private var mainTimeLineRef:*;
private var toPassRef:int;
          public function loads(a:Stage,b:int):void{
stageRef=a;
             toPassRef=b;

Similar Messages

  • How define a global variable in a class that all the methods will recognize

    hi friends,
    i need to define a global variable in a class that all the methods will recognize it.
    any suggestions?
    thanks,
    dana.

    Dera Dana,
    In se24, create your own "Z" class.
    Open the Attributes tab.
    Insert your variable in the declaration part.
    EQ:
    Attribute     Level                       Visibility   Typing      Associated Type         Description        
    ITAB     Instance Attribute     Public     Type     Structure name     Description
    In the Layout of View page,
    <phtmlb:formLayoutDropDownListBox id                = "Dropdown"
                                              label             = "Drop Down"
                                              table             = "<%= controller->Itab %>"
                                              nameOfKeyColumn   = "CODE"
                                              nameOfValueColumn = "VALUE"
                                              selection         = "<%= controller->feild to be selected %>"
                                               />
    Hope this will be helpful
    Regards,
    Gokul.N

  • How to get name of class that the JVM was started with ?

    Assume I have class foo with the standard main method.
    I also have classes ding and dong, they extend foo.
    The JVM is started with either ding or dong as the 'main' class. Since neither ding nor dong directly implement main, the actual main method being executed is foo's.
    In the main method of foo I want to construct an instance of either ding or dong, depending on which the JVM was started with. Since I'm in a static context, I can't do anything with 'this'. Is there another way to get the name of the 'main' class from the JVM so that I can construct an instance of it ?

    The idea behind all of this is that the developer of
    Ding and Dong should not have to know anything about
    foo, in particular it's constructors. But if Ding and Dong are subclasses of Foo, then developers must know about Foo. If you expect developers to extend a framework without having a well-defined interface to that framework, you are probably heading for trouble.
    To be able to
    privatize the constructors, construction of the
    concrete class has to take place in foo.If Ding and Dong are subclasses of Foo, then you can not make all of Foo's constructors private.
    Of course I could have a method in Ding and Dong that
    calls a static method in foo into which the Ding and
    Dong instance pass their class, but then I'd have
    identical implementations of this method in Ding and
    Dong. Yes you would (well, not identical, but very similar). Like I said, you could do this programmatically with AOP, or you could probably do it dirtily using stack traces (though with it being a single hit at startup, you might not consider it being quite so dirty).
    But: the point of inheritance is that common
    functionality goes into superclasses. I disagree. The important thing about inheritance is that classes share an interface, and that methods can be polymorphically inherited, allowing new functionality to be 'plugged in' in the future, and even at runtime.
    Also, in
    general one wouldn't make methods static if a class
    reference is needed (or one would make it an
    argument), but Sun didn't consult me when they
    designed the main method :-(I still don't see why you need to do what you want to do. It appears that all you are after is the ability to start your program using a command line like
        java com.mypackage.Ding
    instead of
        java com.mypackage.Foo com.mypackage.Ding
    or
        java com.mypackage.Foo Ding.properties
    or something else along these lines.
    Since you must know the name of the class you want to use at the time you want to use it, why can't you just pass the name as an argument, or start up using some properties file, or a shell script?

  • Passing Variables from One Class to Another

    Hello, I am new to Java Programming and I'm currently starting off by trying to build a simple application.
    I need help to pass variables created in one class to another.
    In my source package, I created 2 java classes.
    1. Main.java
    2. InputFileDeclared.java
    InputFileDeclared reads numerical data from an external text file and store them as string variables within the main method while Main converts a text string into a number.
    Hence, I would like to pass these strings variables from the InputFileDeclared class to the Main class so that they can be converted into numbers.
    I hope somebody out there may enlighten me on this.
    Thank you very much in advance!

    Values are passed from method to method, rather than from class to class. In a case such as you describe the code of a method in Main will probably call a method in InputFileDeclared which will return the String you want. The method in Main stores that in a local variable and processes it. It really doesn't matter here which class the method is in.
    You InputFileDeclared object probably contains "state" information in its fields such as the details of the file it's reading and how far it's got, but generally the calling method in Main won't need to know about this state, just the last data read.
    So the sequence in the method in Main will be:
    1) Create an new instance of InputFileDeclared, probably passing it the file path etc..
    2) Repeatedly call a method on that instance to return data values, until the method signals that it's reached the end of file, e.g. by returning a null String.
    3) Probably call a "close()" method on the instance, which you should have written to close the file.

  • Best name to class that Do something....

    Hello !
    I have a doubt about naming Java classes that do something..
    Example: I have a class that calculate an range of year available to generate an report. This class return a list with Last 5 years from 2011... ex: in 2013 the list will return 2012, 2011 etc...
    How can i naming this class?? Its consufing because in the naming conventions it must be an name and not a verb.
    Thanks !

    PaulH wrote:
    Example: I have a class that calculate an range of year available to generate an report. This class return a list with Last 5 years from 2011... ex: in 2013 the list will return 2012, 2011 etc...Is that all the class does? It just has that one method? And the method does nothing more than create a list of Integers corresponding to the last 5 years? If so, then I would probably not create a whole class just for that. And if that's not all it does, then it's hard to suggest a name without knowing more about what it really does.
    However, its name should come from a word or phrase that summarizes it responsibilities. The name ReportHelper that was already suggested may be appropriate, or perhaps ReportUtil. On the other hand, if the class isn't specifically just for reports, but does a handful of common tasks that deal with times and dates and calendars that could be used elsewhere in your app, then perhaps TimeUtil, or CalendarHelper would be appropriate. Or, if it is just the one method, then maybe that method should be moved to a ReportGenerator class, where calculating the list of years is one step in the task or generating a report.

  • Passing variables to other classes

    Hi the problem im having is ive made 3 classes class A, A1 and A2 when i create A i also create A1 what i am wanting to do is if a condition in A1 is met it will pass a variable to A so A can delete A1 and then create A2, im having some dificulty in passing this variable back to A.
    Any help appreciated

    You mean you want to return a variable from a method in class A?
    Read:
    http://java.sun.com/docs/books/tutorial/getStarted/application/objects.html

  • Passing variables among Jframe classes

    I have 2 Jframes and i want one frame to read a variable in the other frame..
    How can i do that?

    It's better practice, really, handle the data from a frame in a more abstracted form, and keep the details of the form elements etc. within the extended frame object.
    Say, for instance, one frame has a text account number field then.
    public class AccountFrame extends JFrame {
       private JTextField accountField;
       public String getAccountNumber() {
          return accountField.getText();
      public String setAccountNumber(String newAccount) {
           accountField.setText(newAccount);
    ...Where there's a whole bunch of fields, then you should consider a "data transfer object", a separate class, usually a bean, which holds the values from the frame as Strings etc..

  • JSP Accessing variables in a class that are located outside of the class

    I am having a problem accessing a nested HashMap in a function. The HashMap is defined before the HTML starts and the function is located near the end (Shouldn't make a difference).
    List tires = databean.getTires();
    Map frontTireInfo = (Map)tires.get(0); //Works
    Map rearTireInfo = (Map)tires.get(tires.size()-1); //Works
    Map neumaticos = new HashMap();
    for(Iterator itr=tires.iterator();itr.hasNext();) {
         HashMap tempTire = (HashMap)itr.next();
         String tirePosition = (String)tempTire.get("position");
         neumaticos.put(tirePosition, tempTire);
    <HEAD>. . . </HEAD>
    <BODY>. .
    <%=getTireInspectionTable("FRONT_RIGHT")%> //Works
    </BODY>
    I believe the above stores the tempHash in the tirePosition.
    <%!
         private String getTireInspectionTable(String tirePos) {
              StringBuffer sb = new StringBuffer();
         sb.append("<input type='text' value=" +
    *****<% neumaticos.get(tirePos) %> + " />" ) illegal start of expression
    return sb.toString();
    %>
    Why can I not access neumaticos in the method?
    I am able to call other methods from this one, but not variables.
    If it is possible, please help point me in the correct direction.
    Thanks in advance,
    Mike

    MPDreiding wrote:
         sb.append("<input type='text' value=" +
    *****<% neumaticos.get(tirePos) %> + " />" ) illegal start of expression
              Illegal start of expression sounds like a compile time error so your syntax is wrong. Why are you using scriptlet
    <% neumaticos.get(tirePos) %>
    inside of declaration? I think that's the problem. Just remove <% and %> and see what happens.

  • Using the "this" operator to pass variable references among classes and met

    Hi guys still trying to understand how to use the "this" operator
    can some one tell what I am doing wrong or just make this work for me to see how it works.
    public class ReferencePassing
    public static void main(String[]args)
    ReferencePassing rp = new ReferencePassing();
    System.out.println(rp);
    public ReferencePassing()
    HelperObject ho = new HelperObject(this);
    System.out.println(this);
    class HelperObject
    private ReferencePassing MyReferencePassingBuddy;
    public HelperObject (ReferencePassing theRp);
    MyReferencePassingBuddy = theRp;
    print();
    public void print()
    System.out.println(MyReferencePassingBuddy);
    }

    Hi guys still trying to understand how to use the "this" operatorYou're still trying to understand how to write methods and constructors.
    public HelperObject (ReferencePassing theRp);Syntax error at ';'.
    MyReferencePassingBuddy = theRp;
    print();
    public void print()Syntax error: '}' expected.

  • Equating a passed variable to another variable??

    I have a simple 3 part setup as follows...
    1 JSP, 1 Java Class, 1 Interface for the class
    I want the JSP file to pass a variable to the java class which contains the name of a variable in the interface. (e.g. a String called "name", the variable name in the interface contains "Bob Smith") How do I get java to equate what is in the passed variable ("name") to what is contained in the name variable of the interface("Bob Smith"). Hopefully I explained this with enough detail to understand, but if I didnt, let me know.
    -Adam Wachtel

    Nevermind, I'm going to switch the flow of data so I dont have to do that.

  • Error: Cannot find symbol: Variable Name

    Hi Guys,
    I'm having some trouble with a piece of code. The error that I'm getting is:
    program.java:17: cannot find symbol
    symbol : variable name
    location: class program
    name.CTI(names[0].charAt(0));
    ^
    My Code is shown here:
    import java.io.*;
    import java.lang.*;
    class program{
         public static void main(String[] args){
              String names [] = {"brian", "stu", "mouse"};
              program name = new program ();
              name.sortArrayStr(names);
              //name.CTI(names[0].charAt(0));
         public void sortArrayStr( String[] names ){
              name.CTI(names[0].charAt(0));
         public int CTI ( char letter ){
              char c = letter;
            int k = (int) c;
            System.out.println("ASCII  = "  + k + ".");
              return k;
    }What I'm trying to do is get the name.CTI method caled from within sortArrayStr. When i call name.CTI from main it works fine, (commented part) but when i try from sortArrayStr I get this problem.
    Anyone have any ideas?
    Many Thanks

    Variable name is a local variable defined in method main, so it can not be referenced by writing name in another method like sortArrayStr.
    The good news is, if you want to call CTI from sortArrayStr, just do it:
    public void sortArrayStr( String[] names ){
        CTI(names[0].charAt(0));
    }

  • Using variable name for Netstream Publish() (actionscript)

    Relatively new to Actionscript.  In the netstream publish() or play() methods, can I pass variable names to the methods instead of hard-coding the stream name?
    Example:
    private function publishLiveStream():void
                ns = new NetStream(nc);
                ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                ns.client = this;
              // blah blah other stuff...
               ns.publish("thefilename", "record");
    I want to replace "thefilename" with a value passed from an input box or use dynamic naming (i.e. current date & time).

    you can use in procedure using sunopisis technology
    OdiExportMaster "-TODIR=/temp/" "-ZIPFILE_NAME=export.zip" "-XML_CHARSET=ISO-8859-1" "-JAVA_CHARSET=ISO8859_1" "-EXPORT_VERSIONS=YES"
    or you can use (unix System)
    OdiExportMaster "-TODIR=/#v_FileName" "-ZIPFILE_NAME=export.zip" "-XML_CHARSET=ISO-8859-1" "-JAVA_CHARSET=ISO8859_1" "-EXPORT_VERSIONS=YES"
    Hope it will work
    Thanks

  • Changing variable name

    Hello all,
    I have build a query with a variable fiscal period. I used this variable in input forms in Visual Composer (@fiscal_period) and in BW reports.
    Now end users ask me to change the name of the variable to 'period'. Does this have impact on the existing Visual Composer model?
    Thanks in advance,
    Ralph

    Hi,
    You just change the variable name. After that you need to map again it with input form field as @period, Otherwise it will not get the value. Just map it and deploy it again.
    Thanks
    Chandan

  • How to pass a variable from one class to another class?

    Hi,
    Is it possible to pass a variable from one class to another? For e.g., I need the value of int a for calculation purpose in method doB() but I get an error <identifier> expected. What does the error mean? I know, it's a very, very simple question but once I learn this, I promise to remember it forever. Thank you.
    class A {
      int a;
      int doA() {
          a = a + 1;
          return a;
    class B {
      int b;
      A r = new A();
      r.a;  // error: <identifier> expected. What does that mean ?
      int doB() {
         int c = b/a;  // error: operator / cannot be applied to a
    }Thank you!

    elaine_g wrote:
    I am wondering why does (r.a) give an error outside the method? What's the reason it only works when used inside the (b/r.a) maths function? This is illegal syntax:
    class B {
      int b;
      A r = new A();
      r.a;  //syntax error
    }Why? Class definition restricts what you can define within a class to a few things:
    class X {
        Y y = new Y(); //defining a field -- okay
        public X() { //defining a constructor -- okay
        void f() { //defining a method -- okay
    }... and a few other things, but you can't just write "r.a" there. It also makes no sense -- that expression by itself just accesses a field and does nothing with it -- why bother?
    This is also illegal syntax:
    int doB() {
          A r = new A();
          r.a;  // error: not a statement
    }Again, all "r.a" does on its own is access a field and do nothing with it -- a "noop". Since it has no effect, writing this indicates confusion on the part of the coder, so it classified as a syntax error. There is no reason to write that.

  • Presentation Variable name being passed as value

    I have a requirement where value needs to be checked against two separate fields for filtering (as OR statement). But there should be ability to filter on these fields separately as well.
    Dashboard prompt:
    Province [Multi search]
    State [Multi search]
    Combined search (Province OR State Fields) [Edit Box] --- used to pass presentation variable
    Report filter:
    Province is prompted
    AND State is prompted
    AND Province is @{presentation_variable} (no default)
    OR State is @{presentation_variable} (no default)
    But if the text field with presentation variable in not used to filter, then the report shows no result because the presentation variable name itself is taken as a value. Any solution how this can be done making sure that if province only is searched for then the presentation variable is not passed as value and the query returns no results?
    Thanks everyone.

    Thanks Rachit, that helps. For the scenario mentioned initially, even this works:
    Province is @{presentation_variable} (no default)
    OR State is @{presentation_variable} (no default)
    But the challenge is if I want to add another filter (like country) also as a filter. When users filter only on country, then the report shows no results because no value has been passed to the presentation variable and the query generated uses presentation variable name as the value!

Maybe you are looking for

  • Time Machine Migration

    Can anyone please help with my time machine problem. I partitioned an external hard drive and use one partition for time machine and one for back up using Carbon Copy Cloner. The plan being if my hard drive goes down I get a new one reinstall from ba

  • I need Java code for a simple graphical hit counter for a webpage

    I was wondering if anybody out there could send me some code for a simple graphical hit counter for a webpage. All the sites that I've visited are garbage and of no use to me. Please help me. Colin

  • [Bug?] DSC - Registering for Server Events

    [LV2009, Win 7 Pro] Howdy (Ben S another one for you? ) I am trying to register for alarm events. This works fine by using the Register for Shared Variable Events method. Since I have a lot of SVs and a dedicated server, I thought listen to the serve

  • My ipod has stopped!

    I was just lisening to my ipod on my ipod speakers and suddenly it just stopped, the music just stopped so i checked what it is and everything on my ipod had frozen, the time isnt moving, the song isnt playing the page isnt changing when i try to cha

  • Cannot access address book following archive and install

    Following an archive and install with 10.5.8 I find that when attempting to access Address Book, Font Book, Text Edit and Time Machine I get the following admonition on the screen, " You can't open the application because it is not supported on this