newbie on passing variables between functions

Hi, I'm new to flash development and did only Java, C++, assembler before. This issue will be probably fairly simplistic. I want to click on a button, which will then call on another method, pass it several integers (ints) and the method returns an int after certain operations. Here is a snippet of my code.

package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.media.Sound;
    import flash.text.TextField;
    import flash.text.TextFormat;

    import mx.controls.Text;

    import qnx.ui.buttons.Button;
    import qnx.ui.buttons.LabelButton;
    import qnx.ui.text.TextInput;

    import spark.components.TextArea;

    // The following metadata specifies the size and properties of the canvas that
    // this application should occupy on the BlackBerry PlayBook screen.
    [SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
    public class AIRHelloWorld extends Sprite
    {
        public function AIRHelloWorld()
        {
            //var R1 R2 and R3 are declared and read from here. 

//here is where the call should happen
//calculation button
            var total:Button = new Button();
            total.addEventListener(MouseEvent.CLICK, calculate, R1, R2, R3); //this should return an int

            //textformat for the calculate button
            var Calformat:TextFormat = new TextFormat();
            Calformat.color = 0xAA0000;
            Calformat.color = 0xAA0000;
            Calformat.size = 24;
            Calformat.italic = true;
            Calformat.align = "center";

            //text for the button
            var text:TextField = new TextField();
            text.text = "Calculate";
            text.setTextFormat(Calformat);

            //add text to calculation button
            total.addChild(text);

            stage.nativeWindow.visible = true;
        }

        private function calculate(event:MouseEvent, R1:int, R2:int, R3:int):int {
            return 0;
        }

        private function closeWindow(event:MouseEvent):void{

            stage.nativeWindow.close();
        }

        private function goToBackWindow(event:MouseEvent):void {
            stage.nativeWindow.orderToBack();

        }
    }
}

Needless to say, Adobe Flash builder don't like what I'm trying to do. Apparently EventListener does that take Boolean arguments. So how the values of R1 R2 and R3 to the function calculate?

Thank you for your time

Hello and welcome:

In Flash/Flex/AIR event model is very simple and flexible.  In your example, it is better to create a LabelButton and add the event listener to that (fewer lines of code).  As:

var button: LabelButton = new LabelButton();

Button.label = "Push Me";

button.addEventListener (MouseEvent.CLICK, DoCalculate);

If necessary, adjust the location

addChild (button);

When the mouse is clicked, a "MouseEvent" event is sent to the DoCalculatefunction.  All event listeners must accept a parameter of an event. All events derive from the class of events 'event '.  Thus, the type of parameter can either be a MouseEvent from that which was given to generate, or the most high quality event.

private function DoCalculate (event: Event): void

{

do something

}

Now what needs to be calculated would be information in the same point of view or accessible to the DoCalculate method.  So if you have 3 domains (e.g., TextInput), then those would be deprived of the main view and then attributes can be used to determine the result of the mouse click.  For example:

SerializableAttribute public class MyApp extends Sprite

{

private var r1: TextInput = new TextInput();

private var r2: TextInput = new TextInput();

private var r3: TextInput = new TextInput();

public void MyApp()

{

Add text entry to display a list

make the application visible

create a button

Add button click listener

}

private function DoCalculate (event: Event): void

{

var sum: int = parseInt (this.r1.text) + parseInt (this.r2.text) + parseInt (this.r3.text);

do something with sum

}

}

Hope that helps.

Tags: BlackBerry Developers

Similar Questions

  • passing variables between the pop-up windows

    I'm moving one popup to the other variables. It works fien if I spend bvariable of main application as soon as I'm moving from variable popup to popup window it does not work here is what I am trying ro:

    That works fine

    hand. MXML

    private function launchMoreInfo (): void {}
    var win: view = PopUpManager.createPopUp (this, opinion, true) as point of view;
    //

    victory. AccountNum = list1.selectedItem.accountNum;
    Win.User = user;

    }

    But if I try to pass variables to the pop-up window, created from popup component, is not ' work

    View.MXML

    private function dsclientevents (): void {}
    var win2:view = PopUpManager.createPopUp (Thi, dsclienteventlog, true) like point of view;
    //

    win2. AccountNum = 'test ';

    }

    AccountNum is declared in dsclienteventlog.mxml

    Is it possible to pass variables between the pop-up windows?

    I would much apreciate your help

    Thank you

    Hi friend!

    I have faced this kind of problem and solved using 'Public static var '.

    Just, you declare a public static variable in your class Popup. Then you can directly set the value to this variable as,

    ClassName.StaticVariableName = value;

    In your case,.

    say PopUp2.mxml or PopUp2.as

    =======

    In the PopUp1 script:

    OnItemSelectionChange (event): void

    {

    PopUp2.m_iSelectedID = DatagridID.selectedItem.AccountID; It will change the value of this variable, even if the popup2 is open.

    your stuff here...

    }

    Try this, I hope this will help you.

    Thank you

    Merlina.

  • Passing variables between LabVIEW and TestStand

    Hello

    I'm just learning how to use TestStand and although there are a multitude of resources available, I always find me at a loss on how to pass variables between TS and LV, leaving me to think that there is one fundamental thing that I'm missing which is likely, given that I have a weeks experience with LabVIEW and a days of experience with TestStand.

    I took a glance to the example of 'Clusters' to the Code Modules in TestStand examples (I use TS 2016 if it matters) because I thought it would be quite ideal for what I hope. In this case, I hope to be able to pass a string (a file path) to LabVIEW and VI power take this string and use it as part of an order for the Exec.VI system.  Then, I would be able to pass strings back to TestStand to show the user if an error occurred, but I thought I should get the first part of work.

    I guess my question is what do I have to wait to see in clusters to the example of the Modules of Code? The Watch window displays all defined variables premise on which has the ContainerOut in the Variables pane, but I don't see any kind of update on facades (VI1.vi and VI2.vi) LabVIEW code. Should I be?

    I looked at a few other discussions of the forum here and here, as well as the document of the basis of knowledge here, but could not recreate their solutions. It seems that the connector pane would be a viable way to go, but I'm not sure on how we create and use effectively. According to this document , it makes it seem like it should be simple enough to makes these terminals, but I am still missing a key step. I was able to follow all the steps on the knowledge base document and run the sequence, but then had no idea if it worked or not; I have the report show me the values of the variables I put, but I have no idea whether or not he actually did anything with the LabVIEW VI, or how I could see that.

    Please let me know if you need further information or clarifaction everything I ask.

    Thank you for your time,
    JColvin

    Digilent, a company of National Instruments

    If you want to enter values, you must create a vi for instance dialog box

    The OK button will allow new values to pass to the output terminals.

    A Cancel button will pass just the original through the output values without alteration. The VI will close when either the OK button or cancel were pressed.

    Concerning

    Ray

  • pass variables between form

    Hello

    I use oracle forms 6i.
    How can I pass variables between Forms?
    Consider the scénarion of a login form.
    Once a user logged in successfully, a new form is displayed, where his name is to be displayed
    like '< user > welcome. '
    If name must be past form at the home page login form.

    Is this possible with Oracle?

    Adkins

    Adkins,

    For Global Variables just assign a value to that, and it's initialization. Or you can use

    DEFAULT_VALUE(NULL, 'GLOBAL.');
    

    Make sure that you assign the appropriate value to the global variable before opening the new form.

    And for the parameter, try.

    DECLARE
         Pl_Id PARAMLIST;
    BEGIN
         Pl_Id := GET_PARAMETER_LIST('tempdata');
         IF NOT ID_NULL(Pl_Id) THEN
              DESTROY_PARAMETER_LIST(Pl_Id);
         END IF;
          Pl_Id := CREATE_PARAMETER_LIST('tempdata');
          ADD_PARAMETER(Pl_Id, '', TEXT_PARAMETER, '');
          Open_form('', ACTIVATE, SESSION, Pl_Id);
    END;
    

    Kind regards

    Manu.

    If my answer or the answer to another person has been useful or appropriate, please mark accordingly

    Published by: Manu. April 14, 2010 09:16

  • Passing variables between Forms

    Hi, I am currently working on a rock, paper, scissors project in my class oracle. I was wondering if an oracle form to pass variables between them. I created a login form, and I would once a user logs on to change his user name to one opponent text fields username in the form of game. Is it possible and in this case you may be able to show me an example of passing variables between Forms? Thank you

    You can use the Globals for this purpose. I mean in your login form when your will enter its correct information then and it press OK to the newspaper by so you can for example store their username in the GLOBAL variable

    :GLOBAL.USERNAME:=:FORM.FIELD_NAME;
    

    This global variable, you can access a form any of the current session.

    -Clément

  • bbUI.js - passing variables between screens

    Hello

    I tried something using the framework bbUI.js and it seems to be pretty easy to use if it becomes more stable in future releases. But I could not find a way to set some global variables between screen-change (push and pop/back). Is it possible to define some vars on the bbUI init and use them on a screen to change the values and also back on the same screen to read values?

    Concerning

    Hello!

    Please search the forums before posting

    http://supportforums.BlackBerry.com/T5/Web-and-WebWorks-development/how-to-pass-params-to-the-next-s...

    See you soon

  • pass variables between classes

    Hello! I'm new to flash actionscript and I make a small game right now. I thought to create separate movieclips for each level of play and their assigned separate classes is cleaner and easier to code.

    for example: -.

    level 1 - level1.as

    level 2 - level2.as

    Level3 - level3.as

    My problem is how to pass variables (such as health, score, etc.) to a higher level?

    Please help I'm stuck on this and I have searched a lot but couldn't get the right answer...

    Oh, and I use cs3 flash with actionscript 3.0

    I don't think you really understand what are classes and movieclips.

    MovieClips are display objects; your character, the enemy, elements, platforms< these="" will="" be="">

    Classes can be used to define new elements or extend those which already exist, such as an object or a MovieClip.

    For the purposes of making a game, I would separate levels of executives.

    do level 1 on a frame labeled "level 1".

    and level 2 on a frame labeled "level 2".

    variables will carry an image to the image.

    Use gotoAndStop (frame_label) to switch between levels

    * Make sure you use stop(); on the first image to prevent bike between the frames.

    * You can make the frames between each level that has the code "gotoAndStop(previous level)" to prevent people to hit 'play' on the swf file and the cycling through your levels.

    You can also search for SharedObjects as a method of storage of variables even after that the swf file is closed.

  • Problem with counting function, passing VARs between functions.

    Hi guys, I have a problem with this section of code...

    Could anyone suggest how to fix the function at the bottom so that when the button forward_btn with label "go to next Point training" when you click on recalculate the fields created in the function fileLoaded

    var xmlData:XML = new XML ();
    var theURL_ur:URLRequest = new URLRequest ("xml.xml");
    var loader_ul:URLLoader = new URLLoader (theURL_ur);
    var more: RegExp = / \ + / g;
    var t:Number = 0;
    var tmax:Number = 0;

    loader_ul.addEventListener ("complete", fileLoaded);

    function fileLoaded(e:Event):void {}
    xmlData = XML (loader_ul.data);
    Tmax = xmlData.Record.length ();
    trace (tmax);

    trace (unescape (xmlData));
    trace (xmlData.Record.length ());


    var title_tp:String = unescape(xmlData.Record.TP.Title[t]).replace (, "");
    Title_TP_txt. Text = title_tp;

    var intro_tp:String = unescape(xmlData.Record.TP.Introduction[t]).replace (, "");
    Intro_TP_txt. Text = intro_tp;

    static_tp_intro.y = Title_TP_txt.y + Title_TP_txt.textHeight + 10;
    Intro_TP_txt.y = sta_tp_intro.y + sta_tp_intro.textHeight + 5;

    Title_TP_txt. AutoSize = TextFieldAutoSize.LEFT;
    Intro_TP_txt. AutoSize = TextFieldAutoSize.LEFT;
    }

    forward_btn.label = "go to the next Point training";
    forward_btn.addEventListener (MouseEvent.CLICK, next_if);

    function next_if (me: MouseEvent): void {}


    If (t == tmax) {play();  }


    else {t = t + 1;
    fileLoaded () ;}
    }

    I don't see where you have a question from vars between functions because you do not pass everything.  Maybe that's your problem.  The function fileLoaded expects an argument, but you are not providing one.  To get around that you should provide any argument being sent in the first function...

    function fileLoaded(e:Event=null):void {}

    Another option would be to separate features and put a quick end to the function fileLoaded and create another function that holds the rest of the code...

    function fileLoaded(e:Event):void {}
    xmlData = XML (loader_ul.data);
    Tmax = xmlData.Record.length ();

    processXMLData();

    }

    function processXMLData (): void {}
    trace (tmax);

    trace (unescape (xmlData));
    trace (xmlData.Record.length ());

    var title_tp:String = unescape(xmlData.Record.TP.Title[t]).replace (, "");
    Title_TP_txt. Text = title_tp;

    var intro_tp:String = unescape(xmlData.Record.TP.Introduction[t]).replace (, "");
    Intro_TP_txt. Text = intro_tp;
      
    static_tp_intro.y = Title_TP_txt.y + Title_TP_txt.textHeight + 10;
    Intro_TP_txt.y = sta_tp_intro.y + sta_tp_intro.textHeight + 5;
      
    Title_TP_txt. AutoSize = TextFieldAutoSize.LEFT;
    Intro_TP_txt. AutoSize = TextFieldAutoSize.LEFT;
    }

    forward_btn.label = "go to the next Point training";
    forward_btn.addEventListener (MouseEvent.CLICK, next_if);

    function next_if (me: MouseEvent): void {}

    If (t == tmax) {}

    Play();

    } else {}

    t = t + 1;
    processXMLData();

    }
    }

  • OOP - how to pass variables between the branches of the object, but not instances of VI

    I have a main VI where a thread object goes through some subVIs initialization and then branches off into several parallel loops. My understanding is that each branch becomes a separate instance of the object. Data is passed between the loops using global variables, wrapped in the accessors (I can change this if someone has a better approach - reducing to a minimum the memory and the CPU usage is very important).

    I need to have a large number of instances of the main VI running at the same time. What would be the best way to ensure that the data transmitted between the loops of one instance of VI do not interfere with the data transmitted between the loops of another instance of VI?

    Thank you for your understanding.

    Ah, you're right. Stupid mistake on my part. It's all working now. The corrected code is attached.

  • Newbie question - passing variables (aka why this work?)

    I spent a few hours in vain trying to pass the value of a html text box to a coldfusion page 2nd via the URL (query string).

    However, it seems that I can't do this because the 2nd page seems to be able to reference the value in box of text in any case.  My question is: is this a coincidence, or is this the normal procedure, things work?  When I click the "Run report" button, everything I typed in the text box appears on the screen of page2.cfm.  I thought I should pass this value somehow (via the variables session or the URL string or something).

    So my newbie question is: is this the way it should work (a simple answer Yes or no is fine)A text from one box. CFM file can reference the value of text box on the other. CFM page? Thanks in advance

    Here is the page 1 (page1.cfm):

    <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional / / BY" > ".
    < html >
    < body >

    " < CFform action = ' http://www.mywebsite.com/page2.cfm "method ="get"> "
    Cust ID: < cfinput type = "text" name = "CustomerID" >
    < input type = value = "run report" >

    < / CFFORM >
    < / body >
    < / html >

    Page 2 (page2.cfm) here which works fine and shows what I typed in the text box:

    < CFOUTPUT >
    #CUSTID #.
    < / CFOUTPUT >

    I was already typing this until Ian replied. But I may as well post it in case it helps...

    > I spent a few hours * in vain * trying to pass the
    > value of a html to a coldfusion page 2nd text box via the
    > URL (query string).

    If you know that he or she is actually what you 're doing.

    "> http://www.mywebsite.com/page2.cfm" method = "get" >
    > Cust ID:

    When you use method = "get", the form field, the variables are passed in the query string. So, if you enter "abc" in the text box, the URL submitted will be:

    http://www.mywebsite.com/page2.cfm? CustID = abc

    So 'CustomerID' will be available as a variable within the scope of the URL on page 2.

    > * Here's page 2 (page2.cfm) which works fine and shows
    > what I typed in the text box: *.
    >
    > #CUSTID #.
    >

    The reason for which he works is a little magic CF. The variable #custID # not be bounded, CF search this variable in a predefined list of staves (see link below). It looks in each of them, and uses the first value it finds. Although not the exact search order, CF will check the

    http://livedocs.Adobe.com/ColdFusion/8/Variables_32.html
    -VARIABLES in scope (at the time..)
    -Reach URL (at the time..)
    -FORM scope (at the time..)
    ... etc...

    In your case, the variable exists in the scope of the URL. If your code is equivalent to saying

    #url. CUSTOMERID #.

    It is in fact a practice better coding. Although the original code works without the scope of variables, providing an explicit framework is more efficient and avoids unitentional errors.  For example if the code on page 2:


         #CUSTID #.

    ... the output may not be what you would expect ;-)

    So to answer the question: Yes, that's what must happen.  However, you must explicitly scope your variables page 2 IE use #url.custID #.

  • Passing variable to functions

    Try to pass the t.content variable to a function called mp3player. trace works when the function is called, but not inside the function.

    No idea why?
    Thank you.
    -CK

    Try after the line:
    var mp3player:MovieClip = this.attachMovie("mp3player","mp3player",1);
    Mp3Player.xmlFile = xmlFile;

  • How to pass variables between Labview and Teststand

    It is probably a trivial question, but I'm new to TestStand. All I'm doing is updated to a variable in Labview and then pass this value in a local variable Teststand. A simple test that VI is attached. I get no error and it seems correct, but when I followed the variable via TS watch display is not updated. Also I am not able to read the variable outside TS. It is probably a trivial thing, I'm doing wrong, but I'm stuck.

    Too bad, it was simple. Just need to add the context of sequence as input, then set it to ThisContext TS

  • How can I pass variables between the areas?

    So I have a SWF8 file as a player on one area (unsecured).  It loads and plays a SWF8 from another domain (secure).  So far so good.  Problem is, I need the player to send variables to files it's play that links in this SWF will be, in addition, a link.  I also need the player to receive orders from control of film in return.  There must be a rule or two that I am violating, because even if the file is read, everything depends on a variable is just dead.

    A note: the two files started as SWF6.  I understand that I can only make what I'm trying with SWF8, I went into the code and fixed case sensitive issues and made the conversion.

    Can I do this?  If so, how?  Is the script for the variables from another domain different somehow?

    Thanks in advance.

    You can use localconnection() for communication between the two.

    If sovereign wealth funds need to both send and receive data, using 2 instances of localconnection in each swf file.

  • Passing variables between classes

    I think I'm doing this more difficult than it really is. I would like to pass a variable of a class to another, once a file has been loaded. Currently I have a ListLoader that querys a PHP/mySQL which returns the XML of the class. I would like to create another class that processes this XML but I don't know how he pass only after it is loaded. It's getter/setter methods, or am I missing something really simple (or something else entirely)?

    Here are the two classes, with that I fight.

    Because the ListLoader makes the loading and the panels there appear, the panels need to know when the XML is available. If the panels accessed the magazine to the list, they either need to keep control if their XML is loaded, or subscribe to the magazine as a listener. It is better for the charger inform services' (the signs) when to use the XML.

    Better yet, if signs are essentially "views", take the treatment on the XML panels and give him the charger, then pass the XML transformed like a string or an object, or whether you need. In this way, the charger is the 'supply' and not the display panel, and the two don't get merged.

    The next step is to put in another class - essentially a data model that stores everything that has need of a Panel, so you might have different versions of panels, all you have access to the same data model. This class would then become the "model", and the Panel becomes the "viewer". (do a search for 'model view controller' - it's a basic OOP structure that goes a long way to help you think about OBJECT oriented programming, even if you do do not match exactly).

  • How to pass variables between scripts in OpenScript

    I have a script that calls two nested scripts. A single script creates an account number and the other script uses this account number.

    MainScript:
    RunScript: Script1-> 'account number '.
    RunScript: Script2 <-"account number".

    What would be the most effective way to pass a variable to the main script to the secondary ones. OpenScript there overall (or maybe environment) variable I could use?

    Hello

    You're right OpenScript variable will be visible from any script, note however that you will not see them in the list of proxy using the user interface, you need to change the name of the parameter and use the syntax of variables * {{nomvar}} * in any script.

    Concerning

    Alex

Maybe you are looking for