Passing a variable between functions [Silly Question]

Hey, I am trying to write a program (who wouldve guessed) and I have the following problem. I set a variable in one function, but when I access it from another one, it is "undefined". How can I pass the variable, so both the functions see it? I thought the "public" class when defining a function should take care of that, but I was obviously wrong. Please help? (Code following...)
public function dalsi_slovicko():void {
               var pocet_slovicek = slovnikXML.slovicka.elements("*").length();
               var cislo_slovicka = randomNumber(0, pocet_slovicek);
               var slovicko_1 = ask(cislo_slovicka, "en");
               var slovicko_2 = ask(cislo_slovicka, "cs");
               slovicko1.text = slovicko_1;
private function kontrola() : void {
          if (nazor.text == slovicko_2) {
                dalsi_slovicko()
          else {
               Alert.show("Špatně!! \n Slovicko_2 bylo:" + slovicko_2);
Thanks...

create the variable outside the functions so it is accessible for all the functions.
private var slovicko_2;
public function dalsi_slovicko():void {
            var pocet_slovicek = slovnikXML.slovicka.elements("*").length();
             var cislo_slovicka = randomNumber(0, pocet_slovicek);
             var slovicko_1 = ask(cislo_slovicka, "en");
             slovicko_2 = ask(cislo_slovicka, "cs");
             slovicko1.text = slovicko_1;
private function kontrola() : void {
          if (nazor.text == slovicko_2) {
               dalsi_slovicko()
          else {
              Alert.show("Špatně!! \n Slovicko_2 bylo:" + slovicko_2);
Also when you declare variables, set  appropriate datatypes

Similar Messages

  • Please help!! Can I pass a variable between 2 swf's that are on different html pages?

    Hey,
    Does anyone know how to pass a variable (string) from one swf
    to another if there in separate html pages?
    I assume I’d have to send the variable from the first
    page and load it into the second but I don’t know what
    functions or code I should be using. Any suggestions would be a
    HUGE help.
    Thanks
    If it helps: I’m creating a log in and sign up sheet
    that can be accessed from several sites. I’d like to record
    which site the user has come from when they signup.
    Thanks

    if they are open at the same time (for the same user), you
    can use the localconnection class to communicate between the
    two.

  • How can I pass a variable between JSP and Role Form

    I need to pass a variable from (a copy of) applicationmodify.jsp to the IDM Role Form so that the variable is available within the Role Form at display. We've tried getAttribute and setAttribute modifying both the Role Form and the applicationmodify JSP and can get the form to the role form but not accessible but have had no other success. Has anyone had any success in doing this? Any suggestions would be appreciated.

    if by _root level you mean you're loading something into
    _level0 you can't won't be able to use the localconnection. the
    sharedobject is your only option.

  • Passing a variable between applications

    Hi,
    I would like to pass a variable from a jsp page in a portal application into KM repository filter with user session context. For example, I will set { var1="sample data" } in the portal application and read it in the repository filter. Actually I am looking for a model like import/export statement in ABAP.
    Thank you,
    Orkun

    Hi Orkun
    Considering you aren't trying to send the variable in your url, you must concatenate your variable inside your well formed url and it must be considered during the iView configuration in your portal.
    KM is able to get all posts from the client once you have informed first the name of variable that  you are posting in your form.
    There's no need to use session context at this point, we must consider session contexts when talking about statefull session beans.

  • Passing Array variables between objects

    While troubleshooting a Flash app, it took me hours to figure
    out that you need to make a duplicate of an Array variable if you
    are passing it between objects. Otherwise, any alterations that you
    make to the array will result in the original array being altered
    as well as the "new" array.
    I'm no developer, can someone please explain why you have to
    do this? Or, give me an instance when you wouldn't want to make a
    duplicate? Just trying to understand.
    Thanks.

    it is because if you do something like this
    a=[1,2,3]
    b=a
    all you are doing is storing a reference to a in a variable
    b.Instead, either copy oput the array again or use one of the array
    methods which return an array eg
    b=a.slice()
    b=a.concat()

  • How to pass local variables between different sequence files?

    Actually i want to pass the data (local variable) from my process model file to a client file. The client file only has the callbacks and those callbacks require some parameters as input which is available in local variables of my process model sequence file. I do not want to use Station Globals.
    Please tell me any other way by which i can pass that data.

    Which Locals do you want from the model.  Every sequence has it's own Locals and there are a bunch of sequences in every process model.  Do you want the entry point's Locals?  A callback's Locals?  Just one of the sequence's Locals?  Some Models have way more entry points than others.  What if your sequence file is ran with a different entry point?
    One option is to create your own callback in the model and pass the data to it as parameters.  Then add that callback to your client sequence file and get it out of the parameters.
    If you simply want the entry point's locals and you are in your Main Sequence then you could use RunState.Caller.Locals.VariableName.  This assumes you will use the same entry point every time you run that sequence file.  Or assumes that every entry point you run has the same Local variable name.
    Maybe there is an API method that exposes what you are looking for.  What is your goal?
    Regards,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • Passing array variables into functions (and why I'm hopeless at arrays)

    OK, I have spent a day on this now and have done some fairly
    extensive searching online. The problem is - I am hopeless with
    arrays (and probably just actionscript generally for that matter)
    I want to create an array of buttons, so I set up an array of
    actions, step through each item and then try to pass that array
    action into an onclick button for an attached button
    The problem I have is that the onclick function ALWAYS
    returns the last item in the array.
    Help!
    Code below:
    ----------------------------------------------------------------

    the reason for this, is that once the for loop executes, the
    'last' value is the only one remaining. what one needs to do here
    is 'store' the string in a newly created property on each button,
    like this:

  • Help: I am trying to pass a variable between classes

    I am trying to pass data in a variable inbetween two classes is there any suggestions as to how to do this? Here is a example of the code I am trying to pass MqMessage to the class MqLog.
    if(MqMessage.equals("END"))               
                                       finalize();
                                       System.exit( 0 );
                             else //else build flat file and launch docusolve
                                       MqLog tempMqLog = new MqLog();
                                       tempMqLog.levelThreeDiagnostic();
                                       aRuntime = null;
                                       aProcess = null;                                   
                                  }

    I don't really undestand what you are asking specifically. If you only want to transfer a value from one Object to another Object, then you should just use a set method:
    if (objectOne.getValue().equals("END"))
    end();
    else
    objectTwo.setValue(objectOne.getValue())

  • Re: Passing a Variable Between 2 Classes (school project)

    return job.customerCode(custCd);There is no customerCode() method, there is also no custCd variable.

    public double getApplicableDiscount()
        return applicableDiscount;
    }There is no applicableDiscount variable.

  • Passing string variables between servlets

    Hello
    I need to pass an SQL string constructed in Java servlet A to Java servlet B where it can be executed.
    For example:
    In servlet A I have:
    String cmd = ("select x from y where z");
    cmd is then passed to the server as a hidden form field and read by servlet B as:
    if (paramName.equals("cmd")) {
    String cmd = paramValue;
    However, displaying cmd in servlet B shows only:
    "select"
    Is there a way around this at all? That is, other than converting all spaces to another character in servlet A and reinstating the spaces in serlvet B?
    Thanks
    Martin O'Shea.

    marti,
    you are posting the form aren't you... not getting it?
    I'm suspecting that it's a side-effect of URL rewriting.
    http://en.wikipedia.org/wiki/Rewrite_engine
    And of course a better approach is create user model in the session facade... and if you don't know what that means then forget it.
    keith.

  • Passing a variable between html and jsp

    Hello there,
    I'm writing a simple application to show the use of custom tags. I have an html page with a dropdown box. Based on the selection from the dropdown box what the jsp outputs will be different. Can anyone tell me how to use the variable from the html page in the jsp page? The code is as follows:
    manager.html <form method="post" action="manager.jsp">
              <body>
                   <form>
                        <select name="person">
                        <option value="pevans">PEVANS
                        <option value="mgleeson">MGLEESON
                        <option value="jmolony">JMOLONY
                        <option value="pmccarthy">PMCCARTHY
                        <option value="jwalsh">JWALSH
                        </select>
                        <input type="submit" value="Submit" />
                   </form>
              </body>
    </form>and manager.jsp
    <%@ taglib prefix="man" uri="/tags/weekdayTags"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <table border="1">
         <man:forEachLine manager="html selection" var="line">
              <tr>
                   <c:forTokens items="${line}" delims="," var="field">
                        <td><c:out value="${field}"/></td>
                   </c:forTokens>
              </tr>
         </man:forEachLine>
    </table>Thanks very much,
    Ger

    You need to use the response.getParameter("selectName") method which will return a String with the selected value.

  • Passing a variable from one thread to another

    Hi. I'm trying to produce a chat program in Java but need to pass a variable between two threads. I have included a snipet of the code.
    import java.io.*;
    import java.net.*;
    class IndividualConnection extends Thread
         public Socket clientSocket;
         String userName = "";
         public IndividualConnection(Socket connectingSocket)
              clientSocket = connectingSocket;
    public login(String name)
    userName = name;
         public void messageUser(Socket socket, String msg)
              try
                   Socket newSocket = new Socket("192.168.0.162",5163);     
                   DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());
                   outToServer.writeBytes(msg + '\n');     
              catch(Exception e)
                   System.out.println("The connection with the client has been closed.");
                   this.stop();
    public void run()
         Socket global = clientSocket;
    // etc etc
    A number of threads are created based on code similar to the above. Each thread communicates to a different client on the chat program. However, I want to be able to send messages between the clients.
    Each thread has a method called messageUser(Socket socket, String msg). I should (hopefully) be able to send a message to anyone using the prog if I can access their socket. The problem is that the socket objects for each client is held in the clients own thread. I have tried writing some code to find the Socket object in another thread but to no success. The code I am trying is shown below.
         public Socket findContact(String name)
              ThreadGroup currentGroup = Thread.currentThread().getThreadGroup();
              int numThreads = currentGroup.activeCount();
              Thread[] listOfThreads = new Thread[numThreads];
              currentGroup.enumerate(listOfThreads);
              for (int i = 0; i < numThreads; i++)
                   String threadName = listOfThreads.getName();
                   if (threadName.compareTo(name) == 0)
                   //     Socket tempSocket = threadName[i].getClass().getField(clientSocket);
              return tempSocket;
    The line I have commented out does not work. Please could someone tell me how to carry out this task. I have spent many hours trying to solve this but am not able to. The chat server is nearly complete now. I just need to find a way of obtaining another threads socket.
    I hope the problem is comprehensible. I have found it difficult to explain clearly. Many thanks.

    Really simple, inelegant solution:
    class MyThread extends Thread {
    Socket socket;
    MyThread( Socket s ) { socket = s; }
    public Socket getSocket() { return socket; }
    }Better: create a master object that includes an array
    of sockets. Each time you create a Thread, update the
    master object's list of sockets with a reference to
    each Thread's socket. Under the current memory model, the socket field should be declared volatile. The proposed new memory model will guarantee that this will work if the socket field is declared final.
    Sylvia.

  • Passing a variable's associated number between "for" loops & functions?

    Hi,
    I seem to be having a problem understanding how variable information can be passed between functions and arrays.
    I have variable "grab" set up as a Number.
    var grab:Number;
    My intent (I'll do my best to explain) is to have a number "attached" to grab when it is first mentioned in this function, itemClick.
    These should be all the relevant arrays:
    clickItemArray = [scene_Camp.wood, scene_Ax.ax]
    itemUsableArray = [wood2, ax2]
    sceneGuyArray = [scene_Camp.guy_Camp, scene_Ax.guy_Ax]
    function itemClick(event:MouseEvent) {
                    for (grab = 0; grab<clickItemArray.length; grab++) {
                            if(clickItemArray[grab].hitTestPoint(mouseX, mouseY, true)) {
                                    addEventListener(Event.ENTER_FRAME, itemRemoval);
                                    sceneGuyArray[grab].gotoAndPlay("guy_Notice");
                                    trace("guy_Notice");
    I would like to have the number established with grab (it would either be a 0 or 1, as clickItemArray,  sceneGuyArray, and itemUsableArray) be able to be passed into the next relevant function, itemRemoval. I was hoping to use variables so I could use the same function for whatever item was clicked upon. For example, if the clickItemArray item was 1 (the ax), then sceneGuyArray[grab] would = 1, and the right frame would play. That number 1 would be transferred to function itemRemoval, where it would constantly be listening for sceneGuyArray[1] also (where "1" would have been established through the initial "grab" in the first function), and react accordingly.
    function itemRemoval(event:Event) {
                    for (var grab2:uint = grab; grab2<sceneGuyArray.length; grab2++) {
                        if (sceneGuyArray[grab2].currentLabel == "guy_NoticeDone") {
                            //removeEventListener(Event.ENTER_FRAME, itemRemoval);
                            trace("cheese");
    I can't get the trace working, though. I'm sure I'm doing something wrong with "for" loops or the if statement.
    Naturally, help would be appreciated.

    I do have an unrelated question, if you happen to see this...
    Is there a way to "nest" for loops? (maybe there's a better term)
    For example, this is part of a function I have
    } else if (canClickBoo == false) {
                            //for the click array
                            for (var u:uint=0; u<clickToXArray.length; u++) {
                                //disable the mouse
                                clickToXArray[u].mouseEnabled = false;
                                clickToXArray[u].buttonMode = false;
                            for (var l:uint=0; l<clickFromXArray.length; l++) {
                                clickFromXArray[l].mouseEnabled = false;
                                clickFromXArray[l].buttonMode = false;
                            for (var o:uint=0; o<clickItemArray.length; o++) {
                                //enable items to be clicked
                                clickItemArray[o].mouseEnabled = false;
                                clickItemArray[o].buttonMode = false;
    Obviously each "for" loop does the same thing, set the items of each array "false" (make them unclickable if "canClickBoo" is false). In case each array has a different length, though, I can't just use a single "for" loop (afaik).
    I'm wondering if, based on what you see (naturally I can post more), I can simplify the code.

  • The function javascript:doSubmit not passing variables between pages

    Hi,
    I have an report that has a link to another page, and I'm trying to pass 2 variables. If I use a target URL as such the variables do not get passed, but if I use a page target and explicitly add the item name and values it works fine. Here is the call I'm using to javascript:doSubmit:
    javascript:doSubmit('f?p=&APP_ID.:32:&SESSION.::&DEBUG.:32, CIR:P32_PROJ_ID,P32_DID:#AWARD_NUMBER#,#ID_PROVIDED#');
    Does anyone have any insights?
    Thanks,
    Joe

    You can't use doSubmit to pass variables; it will only submit your page with the request you passed in.  All normal page processing and branching will be followed..  Why are you using doSubmit?  Just put the URL in the URL field.
    f?p=&APP_ID.:32:&SESSION.::&DEBUG.:32, CIR:P32_PROJ_ID,P32_DID:#AWARD_NUMBER#,#ID_PROVIDED#

  • How to pass variables between loaders

    Hi,
    I am trying to load an image, with descriptive text and a back button on the click of a thumbnail of the image. I am using a MovieClipLoader instance to do this.
    Here are my problems:
    1. I tried loading the image, with the text(which is within an external swf), using the same loader, but since I am placing them dynamically, depending on the dimensions of the image, I need to pass variables between the two. The image loader is taking longer than the text (obviously) but I need the dimensions of the image before I can place the text. How do I do that??
    2. I tried using two loaders, with separate listeners, and the problem once again is that the text loads before the image, and is hence placed with default values instead of the values derived from the image. The code is within onLoadInit(). Is it possible for me to get the dimensions of the image from onLoadStart()???
    3. There is a back button within the text.swf. I want the image and the text.swf to be unloaded when this button is clicked. How can I achieve that? Can I call loader.unloadClip(target), from within this? Will it recognize the variable?
    4. Is there a much easier way to do this, which I am sadly unaware of?
    Any help will be appreciated.

    Tried the onloadstart() function, but it gives target._width and _height as 0. So that is ruled out...any other suggestions?

Maybe you are looking for

  • Problem in using InitialContext to do a lookup of CMP EnitityBean.

    Hi, I am running WLS 5.1 SP6 on Windows98. I am trying to lookup a CMP entiry bean from Java 1.3 client. I can successfully create the InitialContext but having trouble in using it to do the lookup. I get the following error: jndiContext is javax.nam

  • Lumia 920 - internet sharing doesn't work: Connect...

    Hello all, I'm experiencing a serious problem with the lumia 920. It seems impossible to share my internet connection. Something I normally use for several hours a day. If this problem can't be fixed soon, ill be forced to swithc back to iphone or ht

  • PC Suite for any Dual Sim Mobile

    Is there any nokia dual sim mobile which works with PC Suite ???

  • Module Pool Programming - noninput screen

    Hi Folks, I have a requirement where i need to have check box.When check box is checked screen fields should be enabled else it should be disabled. Please suggest me. If the checkbox is checked fields should become mandatory. Please suggest

  • Lost search function on mini player

    i've lost my search funtion on my mini player, along with what's playing next playlist, any suggestions? Thanks