How to pass a variable between classes?

Hello

I created a class .as MovieClip to a MovieClip that contains 7 buttons. I use a table of these buttons and an array of labels of image on the timeline of the MovieClip parent to navigate in the labels.

...

private function clickHandler(event:MouseEvent):void 
        {
//Sets the current button listed in the button array    
 currentButton = MovieClip(event.currentTarget);
            index = buttonArray.indexOf(currentButton);
        
//Uses the index variable to find the corresponding frame label from the label array            
MovieClip(root).gotoAndStop(labelArray[index]);
        }

...

This works perfectly.

Now I have another .as MovieClip class, I created a simple MP3 player MovieClip. I'm pulling in a XML data of each mp3, including the URL, etc... All works perfectly.

I'm trying to use the variable "index" of the class Nav.as in the class AudioPlayer.as to play the corresponding number of the song. By calling "playSong (index);

"playSong (index);" works in a test file, when I tested the navigation tables and the corresponding number xml concept. I need to shoot the variable 'index' from Nav.as to AudioPlayer.as.

...

private function playSong(mySong:Number):void 
        {            
            var myURL = my_songs[mySong].@URL;        
        
            if (my_channel) {
                my_channel.stop();
            }
        
            my_sound = new Sound();
            my_sound.load(new URLRequest(myURL));
            my_channel = my_sound.play();
        }

private function onPlay(e:MouseEvent):void {            
     playSong(index);
        }

It works perfectly when tested. For example: "playSong (2)" or "playSong (5)" plays the song number correct.

Thank you in advance!

You should not have a currentIndex in each class, simply on the mother of the other 2 classes. When you say 'this.parent' you access the parent display object. This is where you want currentIndex to exist. If both classes are on the same display list then 'this.parent' will be the same parent and therefore the same variable.

I didn't know what kind of display object container parent was (MovieClip, Sprite, etc.), so I've referenced it let go like: 'object (this.parent) .currentIndex '.

Should be in NAV. As:

Object (this.parent) .currentIndex = buttonArray.indexOf (currentButton);

AudioPlayer.as should be read through:

playSong (Object (this.parent) .currentIndex);

Tags: Adobe Animate

Similar Questions

  • How to pass a variable to a swf file in another using the Loader?

    I'm loading a swf file from another swf using the method as follows:

    var myLoader:Loader = new Loader();

    addChild (myLoader);

    var url: URLRequest = new URLRequest ("myExternalMovie.swf");

    myLoader.load (url);

    How to pass a variable to the first SWF in the second?

    I'm not sure that "passage" is a term there, given that this generally applies to what happens with functions that can host variables to pass as arguments in the.

    When using the charger, you can assign an event listener to determine whether the activity of loading is complete and have an event handler that targets its contentLoaderInfo property to the event.currentTarget.content, which in your case would be the loaded swf file.  At this point, you can assign a value to a variable in this swf file by targeting...

    var myLoader:Loader = new Loader();

    addChild (myLoader);

    myLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, loadComplete);

    myLoader.load (url);

    var loadedSWF:MovieClip;

    function loadComplete(evt:Event):void {}

    loadedSWF = MovieClip (evt.currentTarget.content);

    loadedSWF.someVariable = ';?

    }

    It is probably possible you may also have the loaded swf the value rtrieve by targeting to the parent swf file, which would be both parents away because of the charger is the relative of the SWF loaded... unevariable = MovieClip (parent.parent) .someValue;

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

  • 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 a variable to the nearby operator

    Hello! does anyone know how can I pass a variable to the proximity operator?

    with this query variable1 and variable2 are read as words, not as variables.

    SELECT *.
    FROM t1
    WHERE CONTAINS
    (essay, "near ((variable1, variable2), 1)'") > 0;

    Thank you!

    Best regards
    Sara

    You may not use a link within a string variable. This is not a restriction of Oracle text, it's just the way bind variable work in Oracle.

    You can build a string literals and variables, although, like this:

    SELECT *
    FROM t1
    WHERE CONTAINS
    (test, 'near(('||:variable1||', '||:variable2||'), 1)') > 0; 
    
  • How to pass a variable value to a Manager click for a function of ACEs?

    I wish I could click a button, pass a value to a variable, then pass this variable to assess within the case routine.

    MXML:

    Click = "someClickHandler (Event);    <!- like the variable to prepare you with the click-> handler

    AS:

    public void genericFunction(event:MouseEvent):void

    {

    Switch (VariableName)

    {

    CASES1:

    action;

    Action2;

    break;

    CASE2:

    action;

    Action2;

    break;

    .

    .

    .

    caseN:

    action;

    Action2;

    break;

    }

    }

    Thank you.

    The click handler is your function to set how you want.

    MXML

    a click = "someClickHandler (event, 5).

    AS

    public function someClickHandler (event: MouseEvent, someVar:int): void

    {

    switch (someVar)

    ...

  • How to pass the variable in the lov using like operator SQL

    Hello.
    I want to use a lov I pass a variable using like operator.
    my query is
    Select empno, name of the table where empno as ': ed %';

    I want to show a % or B empno % so my empno is A001 to A199 AND B001 to B199
    How can I do this?


    regards

    Set the property default_where to the block and run the query

    set_block_property ('myblock ', default_where,' like upper (Ename)' |: mybind |) » %');

  • How to pass a variable to a builder?

    If I have a CFC as below:
    < cfproperty >
    <!--> init() call automatically when the CFC is instantiated
    < cfset init() >
    < cffunction "init" access = output = "public" name = "" returntype = "shoppingCart" >
    < cfargument = 'cartID' type name = "UUID" required = "yes" >
    < cfset variables.cartID = arguments.cartID >
    < cfreturn this >
    < / cffunction >
    < / cfproperty >

    .. . How do I pass a variable required in the constructor? (I use Flex my front end with Flash Remoting to call my CFCS so that I don't this instantiation of ColdFusion).
    Any help appreciated...

    For example, suppose I have the following CFC called test.cfc:








    .. and I have the following cfm file which called it... test. cfm



    This will cause an error indicating the cartID parameter to the init() function was necessary but not last, because the constructor call ( ) does not switch from parameter to the init function. The only way I can get this to work is to comment out the line. I guess I don't need this in my script because I call the method init directly in any case.

    FYI: I did phone selector example Ben Fortas (a good example of creating a simple Flex/CF application):
    http://www.Adobe.com/devnet/flex/articles/coldfusionflex_part3_02.html

  • How to share a variable between the Mathscript Windows and a Mathscript node

    Hello

    I'm trying to share (just) a variable between the Mathscript Windows and a Mathscript node. I don't know why, but the use of the "global" Matlab function makes the mathscript node output formats change.

    I'm looking for a "Mathscript RT V9.0.1 module" as it may seem, there is. French technical support have some difficulty to find...

    Hi patrick33,.

    The code that you have attached should not report an error, so it seems that something has gone wrong with your installation of MathScript. My best guess is that it is the problem that is described in this knowledge base article. Your signature says that you use f3 patch, which is a good start. But the KB lists some other steps to take when you see errors about MathScript, impossible to compile. Can you try the procedure described in the article and let us know if that fixes the problem?

    Thank you

    jattas

    LabVIEW MathScript R & D

  • How to pass a variable to a sub - VI a vi in real-time?

    The main calls a Subvi where there is a loop for. is possible to pass a variable from inside the loop for handmade in real-time, this is while the for loop is still running?

    I tried with a global variable. The global itself is updated, but if I put for the most part the global variable with a wire to an indicator, the indicatore is not updated until what the sub that VI has not completely passed control to hand.

    Is it possible to do?

    If you are running in windows, see example vi

  • How to pass form variable javacript to java BackingBean

    Hello

    I'm trying to pass the variable Javascript (what is written in jspx) method a Java BakingBeanpage.

    Javascript code is shown here:

    <SCRIPT type="text/javascript">
    function OnSave() {
    alert("The signature you have taken is the following data: " + SigPlus1.SigString);
    }
    </SCRIPT>
    
    
    

    of course, this method is called after the use press save button as follows:

    <INPUT id="submit1" name="Save" type="submit" value="Save" onclick="OnSave()"/>
    

    As you can see it this Javascript will notify the result to the user. IAther I want to pass the object ( SigPlus1) to a Java Bean.

    I use the ADF with JDveloper 11.1.2.3 technology

    Here's the answer:

    ADF RichClient API - af:serverListener

  • How to pass the variable in the table?

    Hello. I try to pass the variable created in RTF and after I enter in the table.

    In RTF:

    <? xdoxslt:set_variable($_XDOCTX,_'var',500)? >

    After the table:
    chart:
    .....................
    < DataValues >
    < RowData >
    [< xsl: for each groupe-select=".//ROW[Edad16]" group by = "Edad16" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" > ".
    < cell >
    xdoxslt:get_variable($_XDOCTX,_'var')
    < / cell >
    < / xsl: for each group->
    < / RowData >
    < RowData >
    [< xsl: for each groupe-select=".//ROW[Edad16]" group by = "Edad16" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" > ".
    < cell >
    50
    < / cell >
    < / xsl: for each group->
    < / RowData >
    < / DataValues >
    < / LocalGridData >
    < / chart >

    And it isn´t work :-(

    Any ideas?

    Hi, Benito,.

    It wil work

     
    
  • Pass the URLLoader() variable between classes

    I have two classes. See below.

    What I want to do is quite simple, but I do not know how to do. I want the URLFactory for create table and store it in the variable 'dataArray' and use the table in the main class, by calling the GetList() class URLFactory. I have returns nothing... Please help

    Basically, I need to set a variable equal to URLLoader.data (var something: String = URLLoader.data) so I can use this variable in other classes. WHY ISN'T IT EASIER? Please, I beg you. A solution would be much appreciated.

    package classFiles
    {
    import flash.display.MovieClip;
    Import classFiles.URLFactory;

    SerializableAttribute public class MainClass extends MovieClip {}
    private var _UrlDriver:URLFactory;

    public void MainClass() {}
    _UrlDriver = new URLFactory ('url');
    var temp: Array = _UrlDriver.GetList ();

    }

    }

    }

    package classFiles
    {
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.sampler.Sample;

    SerializableAttribute public class extends MovieClip {} URLFactory

    private var loader: URLLoader;
    public var textData:String;
    public var dataArray:Array;

    public void URLFactory(url:String) {}
    textData = "";
    this.dataArray = new Array();
    loader = new URLLoader();
    loader.addEventListener (Event.COMPLETE, HandleComplete);
    Loader.Load (new URLRequest (url));

    Temp = CreateDataArray();
    }

    function HandleComplete(e:Event):void {}

    textData = loader.data;

    trace (dataArray);

    }

    function CreateDataArray (): void {}

    trace (dataArray);
    dataArray = textData.split ("\n");
    dataArray = textData.split('","');
    }

    public void GetList (): Array {}

    return dataArray.

    }
    }

    }

    Yes, the data loading is not instantaneous.  This is why you use a complete listener in your factory.

    Similarly, you must use a listener in your main class to check if the data is ready.

    p.s. Please check the useful/correct.

  • How to pass a variable list like bind?

    How can I pass a list as a bind variable in Oracle?

    The following query in SQL Developer so work I put ": prmRegionID = 2.

    SELECT COUNTRY_ID,
    COUNTRY_NAME
    OF HUMAN RESOURCES. COUNTRY
    WHERE IN REGION_ID (: prmRegionID);


    The problem is that I can't find how to set ": prmRegionID = 2, 3.

    I know that I can replace ": prmRegionID" by a proxy '& prmRegionID '. The above query will work well with"& prmRegionID = 2" and with "& prmRegionID = 2, 3". "

    But with this solution, I lost all the benefit of the use of bound variables (analysis hard against soft parse, possibility of SQL injection, etc.).

    Can someone tell me what is the approach suggested by Oracle on this topic? My developer work long find too much how, but don't haven't found answer.


    Thank you in advance,


    MB

    Blais wrote:

    The problem is that I can't find how to set ": prmRegionID = 2, 3.

    False problem. The variable string for this binding means create a unique string that contains the text "+ 2.3 +". THE STRING DOES contain TWO VALUES.

    So the real problem is that you are using the INCORRECT data type - you want a data type that can have more than one value string (or digital). This means that using (varchar2) string data type is the type badly - because it contains only a single value.

    You need understand the problem in the first place. If you do not understand the problem, don't understand or understand the solution too.

    What you want to compare? What does the IN clause? It addresses and compares with, a set of values. Therefore, a data type for the variable binding. A data type allows you to assign multiple values to the variable binding. And use this variable of liaison for the set operations and comparisons in SQL.

    Simple example:

    SQL> --// create a set data type
    SQL> create or replace type TStringSet is table of varchar2(4000);
      2  /
    
    Type created.
    
    SQL>
    SQL>
    SQL> var c refcursor
    SQL>
    SQL> --// use set as bind variable
    SQL> declare
      2          names   TStringSet;
      3  begin
      4          --// assign values to set
      5          names := new TStringSet('BLAKE','SCOTT','SMITH','KING');
      6
      7          --// use set as a bind variable for creating ref cursor
      8          open :c for
      9                  'select * from emp where ename in (select column_value from TABLE(:bindvar))'
     10          using names;
     11  end;
     12  /
    
    PL/SQL procedure successfully completed.
    
    SQL> print c
    
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
          7698 BLAKE      MANAGER         7839 1981/05/01 00:00:00       2850                    30
          7788 SCOTT      ANALYST         7566 1987/04/19 00:00:00       3000                    20
          7369 SMITH      CLERK           7902 1980/12/17 00:00:00        800                    20
          7839 KING       PRESIDENT            1981/11/17 00:00:00       5000                    10
    
    SQL>
    SQL> --// alternative set comparison
    SQL> declare
      2          names   TStringSet;
      3  begin
      4          --// assign values to set
      5          names := new TStringSet('BLAKE','SCOTT','SMITH','KING');
      6
      7          --// use set as a bind variable for creating ref cursor
      8          open :c for
      9                  'select * from emp where TStringSet(ename) submultiset of (:bindvar)'
     10          using names;
     11  end;
     12  /
    
    PL/SQL procedure successfully completed.
    
    SQL> print c
    
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
          7369 SMITH      CLERK           7902 1980/12/17 00:00:00        800                    20
          7698 BLAKE      MANAGER         7839 1981/05/01 00:00:00       2850                    30
          7788 SCOTT      ANALYST         7566 1987/04/19 00:00:00       3000                    20
          7839 KING       PRESIDENT            1981/11/17 00:00:00       5000                    10
    
    SQL> 
    
  • How to pass the variable to a swf into another swf

    I declared a variable in the one.fla file

    I open another file swf on a button.

    the code is as follows

    name = 'personName ';

    myButton.onRelease = function () {}

    trace ("liberation" + name);     personName

    loadMovie ("mainPage.swf", _root);

    _root.loadMovie ("mainPage.swf");

    }

    I want the variable 'name' of access to another swf file. IE (mainPage.swf)

    How do I do that?

    You want to use the MoveClipLoader class (using loadClip() and addListener methods) rather than loadMovie so that you can wait for the file to load before you try to access anything in it.  You can create an empty movieclip to load the SWF in, and in this way the loaded file can be targeted using the empty movieclip instance name.

Maybe you are looking for

  • Problem with WiFi network

    Hi, whenever I wake my macbook the next day he fails to connect to my wifi network (what I used perfectly fine the day before). I then start the wizard in Network preferences, and begins to work very well, not even to enter the network password, it i

  • HP probook 4540 print driver s finger

    Hello...! I need the finger print driver for my hp probook 4540 s. I use 8.1 64-bit windows. kindly help me...

  • How to use the administrator password

    This is my first time to use windows live family safety {wlfs} I create just a username {removed privacy} and {removed privacy} password. After creating finsh it is active... All my software is block by admin password... When I entered the password o

  • Impossible to activate microsoft flight sim fsx

    This game has been activated on my computer before, I uninstalled it as it kept crashing, I re installed game works ok but when I try to activate, he repeats to me your servers are busy or an error occurred. Any ideas?

  • HP d103TX UPDATE

    Can I upgrade my HP d103TX 8 GB of RAM? How many DIMMS are present in this model?