Help with public static functions.

Hey everyone, I worked on a problem for a while and have finally understood just wrong. Google is not helped me to find the right way, so I'm posting it here. I sort of understand what's wrong with my code, but I have no idea how to do right. I'm a total noob to AS3, this is my first project.

I have a main FLA file called game.fla with nothing on the stage, starting with. The document class is Main.as (shown below). The main class is supposed to manage the switching between the preLoader, mainMenu and game itself. The preloader loads and the player must press play to go to the main menu. The main menu is controlled by MainMenu.as, which adds event listeners for buttons game, instructions and credits. At the present time, instructions and credits just draw responses. When you click on play, I want to remove the mainmenu (not a problem with parent.removeChild (this)); and add the game. This is my problem comes in. I can't say parent.addChild (game), because honestly, I don't know how (I need to set a variable in hand or MainMenu and must it be public, static, etc?). Simplicity seems to be a function called initializeGame() that I could simply call of mainMenu. Problem: I have to do a static function, which doesn't let me use addChild, removeChild or any other variable that I create. Could someone please explain how I could do this job (even if it means change my structure. "I would be happy to learn a better way to deal with this kind of thing). Also, on a side note: if I can't use the static function with add or remove a child, can I optimize the effect later? I want later in my game, that I would need to call functions between classes, on a button click, for example, that affect the scene (or objects in the scene). Can I do it another way? For example, by clicking on an icon of the video game card clip, I would map the movieclip to load. A function that could be described seems the best way to do it, but I'm sure he can otherwise. Thank you much in advance. My code is below.

Main.As

package
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class Main extends MovieClip
    {
        private var preLoader:PreLoader;
        private var mainMenu:MainMenu;
        private var game:Game;
        
        public function Main()
        {
            preLoader = new PreLoader;
            addChild(preLoader);
            preLoader.gotoAndStop(1);
            addEventListener(Event.ENTER_FRAME, barLoading);
        }
        private function barLoading(event:Event):void
        {
            var total:Number = stage.loaderInfo.bytesTotal;
            var loaded:Number = stage.loaderInfo.bytesLoaded;
            preLoader.loadingBar.scaleX = loaded/total;
            
            if (loaded==total)
            {
                removeEventListener(Event.ENTER_FRAME, barLoading);
                preLoader.gotoAndStop(2);
                preLoader.doneLoading.addEventListener(MouseEvent.CLICK, doneLoading);
                loaded = null;
                total = null;
            }
        }
        private function doneLoading(event:MouseEvent):void
        {
            preLoader.doneLoading.removeEventListener(MouseEvent.CLICK, doneLoading);
            mainMenu = new MainMenu;
            addChild(mainMenu);
            removeChild(preLoader);
        }
        static public function initializeGame():void
        {
            game = new Game;
            removeChild(mainMenu);
            addChild(game);
        }
    }
}

MainMenu.as

package
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class MainMenu extends MovieClip
    {
        
        public function MainMenu()
        {
            playGameButton.addEventListener(MouseEvent.CLICK, playGameButtonFunction);
            instructionsButton.addEventListener(MouseEvent.CLICK, instructionsButtonFunction);
            creditsButton.addEventListener(MouseEvent.CLICK, creditsButtonFunction);
        }
        private function playGameButtonFunction(event:MouseEvent):void
        {
            playGameButton.removeEventListener(MouseEvent.CLICK, playGameButtonFunction);
            instructionsButton.removeEventListener(MouseEvent.CLICK, instructionsButtonFunction);
            creditsButton.removeEventListener(MouseEvent.CLICK, creditsButtonFunction);
                        
        }
        private function instructionsButtonFunction(event:MouseEvent):void
        {
            instructionsButton.removeEventListener(MouseEvent.CLICK, instructionsButtonFunction);
            trace("instructions");
        }
        private function creditsButtonFunction(event:MouseEvent):void
        {
            creditsButton.removeEventListener(MouseEvent.CLICK, creditsButtonFunction);
            trace("credits");
        }
    }
}

In addition, anny comments on my coding habits and how to improve are welcome.

in the hand

var preloader: Preloader = new Preloader (();)

preloader.addEventListener ("preloadCompleted", preloadCompletedF);

in the Preloader, loading complete:

this.dispatchEvent (new Event ("preloadCompleted"));

Tags: Adobe Animate

Similar Questions

  • Help on parameters public static function

    Hello

    I have two functions in the same file, how can I use the first function as a default value in the second function.

    public static function get decimalFormatter1 (): {NumberFormatter

    //

    }

    I have try this:

    public static void secondFunction(param1:String,_param2:Int=0,_ _param3:Function=decimalFormatter1_):Array {}

    //

    }

    Error:-1047: unknown parameter initializer or isn't a compilation constant.

    Any ideas?

    Thank you!

    To work around the problem, you can use null as default, where null means "use the decimalFormatter1. You have to write something like

    public static void secondFunction(param1:String,_param2:int_=_0,_param3:Function_=_null):Array
    {

    trainer: function var = null;

    If (param3 is nothing)

    Formatter = decimalFormatter1;

    ....

    }

  • public static function return an object instance

    create or replace
    Item_object OBJECT TYPE IS
    (item_title VARCHAR2 (60))
    , item_subtitle VARCHAR2 (60)
    FUNCTION CONSTRUCTOR item_object
    RETURN SELF AS RESULT
    FUNCTION CONSTRUCTOR item_object
    (item_title VARCHAR2, VARCHAR2 item_subtitle) RETURN SELF AS RESULT
    , Public STATIC FUNCTION get_item_object (item_id NUMBER) ITEM_OBJECT RETURN
    MEMBER RETURN VARCHAR2 to_string FUNCTION)
    CANNOT BE INSTANTIATED NOT FINAL;


    create or replace
    TYPE item_object BODY IS
    Item_object FUNCTION CONSTRUCTOR RETURN self AS RESULT IS
    point ITEM_OBJECT: = item_object ('generic Title', 'Generic subtitle');
    BEGIN
    me: = item;
    RETURN;
    END item_object;
    Item_object FUNCTION CONSTRUCTOR
    (item_title VARCHAR2, VARCHAR2 item_subtitle)
    RETURN SELF AS RESULT IS
    BEGIN
    Self.item_title: = item_title;
    Self.item_subtitle: = item_subtitle;
    RETURN;
    END item_object;
    * STATIC FUNCTION get_item_object (item_id NUMBER) RETURN ITEM_OBJECT IS
    point ITEM_OBJECT;
    CURSOR c (NUMBER item_id_in) IS
    SELECT item_title, item_subtitle FROM point WHERE item_id is item_id_in;
    BEGIN
    I'm IN c (item_id) LOOP
    agenda: = item_object (i.item_title, i.item_subtitle);
    END LOOP;
    RETURN of goods;
    END get_item_object; *
    FUNCTION MEMBER to_string RETURN VARCHAR2 IS
    BEGIN
    RETURN ' ['|] [Self.item_title |'] ['|| [Self.item_subtitle |'] " ;
    END to_string;
    END;

    Impossible to compile static function get_item_object, can anyone help me please?

    user6446424 wrote:
    all instances of the object, as all the rows in the table

    I think you misuderstand objects. Objects do not come from thin air - it must exist somewhere or should be constructed from the data. Your function constructs the table utem data object. If you have any item in the table, which should be used?

    SY.

  • Help with packages and functions that it

    Hello, I need help with the package.
    I have two tables of the employee base (id, firstname, lastname, etc..) T1 and T2.
    What I need, it's a package and two features inside. First function reads the data from T1 and passes to the second function, where second function reads data from T2 and concatenates the data just read with data from function1 and data T1 + T2 function2 goes on the main program that displays this data.

    So far, I have:
    create or replace type emp_type as object
    (id number,
    firstname varchar(20),
    lastname varchar(20),
    salary number(9,2));
    
    create or replace type emp_type_table as table of emp_type;
    
    create or replace package my_package
    is emp_table emp_type_table:= emp_type_table();      -- *not sure if this line is correct*
    function get_T1_emp return emp_type_table;
    function get_T2_emp (T1_emp in emp_type_table) return emp_type_table;
    end my_package;
    
    -- *confusion begins*
    
    create or replace package body my_package as 
    function get_T1_emp
    return  emp_type_table as 
      emp_table emp_type_table:= emp_type_table();
    begin
         for i in (select * from T1) loop
             emp_table.extend;
             emp_table(emp_table.count):= (emp_type(i.id, i.firstname, i.lastname, i.salary));
          end loop;
        return emp_table; 
    end get_T1_emp; 
    - get_T1_emp function seems to be quite beautiful. At least it works separately
    function get_T2_emp (T1_emp in emp_type_table)
    return  emp_type_table  
      emp_table emp_type_table:= emp_type_table();
    begin
         for i in (select * from T2) loop
             T1_emp.extend;
             T1_emp(T1_emp.count):= (emp_type(i.id, i.firstname, i.lastname, i.salary));
          end loop;
        return T1_emp; 
    end get_T2_emp;
    end my_package;
    
    
    DECLARE
      v_Return emp_type_table;
      v_Return2 emp_type_table;
    BEGIN
      v_Return := get_T1_emp;
      v_Return2 := get_T2_emp(v_Return);
      for i in 1..2 loop
        DBMS_OUTPUT.PUT_LINE(v_Return2(i).id || ', ' || v_Return2(i).firstname || ', ' || v_Return2(i).lastname 
        || ', ' || v_Return2(i).salary || 'EUR');
      end loop;
    END;
    So basically I don't know about my tax package.
    Most important, I don't know how to write the get_T2_emp function. And also not very sure of my main function. Please can someone help my with my problem

    Published by: dber November 6, 2011 21:22

    Published by: dber November 6, 2011 23:38 added
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    Hello

    Here you go

    SQL> DROP TABLE t1;
    
    Table dropped.
    
    SQL> DROP TABLE t2;
    
    Table dropped.
    
    SQL> CREATE TABLE t1 (id NUMBER,
      2                   firstname VARCHAR2(100),
      3                   lastname VARCHAR2(100) );
    
    Table created.
    
    SQL> CREATE TABLE t2 (id NUMBER,
      2                   firstname VARCHAR2(100),
      3                   lastname VARCHAR2(100) );
    
    Table created.
    
    SQL> INSERT INTO t1  (SELECT 1,'SURI','DAMA' FROM dual
      2                     UNION ALL
      3                     SELECT 2,'SRINU','DAMA' FROM dual);
    
    2 rows created.
    
    SQL> INSERT INTO t2  (SELECT 3,'ABC','XYZ' FROM dual
      2                     UNION ALL
      3                     SELECT 4,'DEF','PQR' FROM dual);
    
    2 rows created.
    

    Package code

    
    SQL> CREATE OR REPLACE PACKAGE test_array_pkg
      2  AS
      3    TYPE test_array1 IS TABLE OF t1%rowtype  INDEX BY PLS_INTEGER;
      4    TYPE test_array2 IS TABLE OF t2%rowtype  INDEX BY PLS_INTEGER;
      5
      6    FUNCTION get_t1 RETURN test_array1;
      7    FUNCTION get_t2(p_t1 IN test_array1)
      8    RETURN test_array2;
      9
     10  END test_array_pkg;
     11  /
    
    Package created.
    

    Package body

     SQL> CREATE OR REPLACE PACKAGE BODY test_array_pkg
      2  AS
      3    t1_array1 test_array1;
      4    t2_array2 test_array2;
      5
      6    FUNCTION get_t1
      7    RETURN test_array1
      8    IS
      9
     10      n NUMBER :=0;
     11
     12    BEGIN
     13
     14     FOR i IN (SELECT * FROM t1)
     15     LOOP
     16
     17       t1_array1(n).id:= i.id;
     18       t1_array1(n).firstname := i.firstname;
     19       t1_array1(n).lastname := i.lastname;
     20
     21       n:=n+1;
     22
     23     END LOOP;
     24
     25     RETURN t1_array1;
     26
     27    END get_t1;
     28
     29    FUNCTION get_t2(p_t1 IN test_array1)
     30    RETURN test_array2
     31    IS
     32
     33      n NUMBER:=0;
     34
     35    BEGIN
     36
     37     FOR i IN p_t1.FIRST..p_t1.LAST
     38     LOOP
     39
     40       t2_array2(n).id:=p_t1(i).id;
     41       t2_array2(n).firstname:= p_t1(i).firstname;
     42       t2_array2(n).lastname := p_t1(i).lastname;
     43
     44       n:=n+1;
     45
     46     END LOOP;
     47
     48     FOR i IN (SELECT * FROM t2)
     49     LOOP
     50
     51       t2_array2(n).id:=i.id;
     52       t2_array2(n).firstname:= i.firstname;
     53       t2_array2(n).lastname := i.lastname;
     54
     55       n:=n+1;
     56
     57     END LOOP;
     58
     59     RETURN t2_array2;
     60
     61    END get_t2;
     62
     63
     64  END test_array_pkg;
     65  /
    
    Package body created.
    

    Main script

     SQL> declare
      2
      3     t1_result test_array_pkg.test_array1;
      4     t2_result test_array_pkg.test_array2;
      5
      6  begin
      7
      8    t1_result:= test_array_pkg.get_t1;
      9    t2_result:= test_array_pkg.get_t2(t1_result);
     10
     11    FOR i IN t2_result.first..t2_result.last
     12    LOOP
     13
     14      dbms_output.put_line(t2_result(i).id||' '||t2_result(i).firstname||' '||t2_result(i).lastname);
     15
     16    END LOOP;
     17
     18  end;
     19  /
    1 SURI DAMA
    2 SRINU DAMA
    3 ABC XYZ
    4 DEF PQR
    
    PL/SQL procedure successfully completed.
    
  • Help with JDBC stored functions

    Hello.. Im having problems with my stored functions (java oracle), where I create the functions but then im I call them, it does not return any value (nothing happens after that I called my function). Can someone help me?

    Here's how to create the registered function:

    /************************************************** ****************/
    create or replace FUNCTION insert_client_func (a_client_name IN CLIENTS.client_name%TYPE)

    RETURN VARCHAR2

    IS


    BEGIN

    INSERT INTO CUSTOMERS (client_name)

    VALUES (a_client_name);


    Return a_client_name;

    END;
    /************************************************** *****************/

    Heres how I call it:

    /************************************************** *****************/
    name = "'" + name + "'";

    Command string = "{call insert_client_func("+name+")}";

    try {}
    String url="jdbcracle:thin:@localhost:1521e; »
    this.dbConnection = DriverManager.getConnection (url, "bd2009", "bd2009");
    System.out.println (Command);
    This.callstmt = This.DbConnection.prepareCall (command d);
    this.callstmt.registerOutParameter (1, Types.VARCHAR);
    this.callstmt.executeUpdate ();
    String simpleArray = this.callstmt.getString (1);
    System.out.println (simpleArray);

    this.dbConnection.commit ();
    This.callstmt.Close ();
    this.dbConnection.close ();
    }
    /************************************************** *****************/

    The syntax of your call is incorrect. For functions, it should be

    "{ ? = call insert_client_func (?)} »

    You can also use the syntax of PL/SQL

    ' BEGIN?: = insert_client_func (a_client_name =>?); END; »

    Then configure your settings

    this.callstmt.registerOutParameter (1, Types.VARCHAR);
    this.callstmt.setObject(2, );

    What is the data type of IN_CLIENTS.client_name?

    Call the function and retrieve the return value

    This.callstmt.Execute ();
    String value = this.callstmt.getString (1);

  • I need a little help with the INSTR function

    Hello everyone,

    im still new to pl sql and experienced an issue with the INSTR function. I need to analyze some values of a CLOB containing the xml code and use INSTR to determine the beginning and end of the value, I would like to analyze.

    the data I need is in a <!-[CDATA [[Some Text]]]-> block. up to this point, I managed to take the start of the word, but I can't seem to capture the end of the CDATA block. I use this statement:

    POS: = INSTR (TO_CHAR (input_clob) [,'] ', pos2 + 6, 1);

    but it doesn't have the desired effect. [It seems to sort of go back to the length of the string, while the]-sign is actually in the xml file. my result would look to "Some Text]]--> < xmlxml >... < / xmlxml >...» ». [I tried to escape by writing ' \] "but if I do, the function returns zero and my parsed string is left blank.

    Unfortunately I can't use regular expressions, because I work with oracle 9.2i. Anyone know what I'm doing wrong?

    Thank you

    Edited by: user8719779 the 25.08.2009 02:23
    with my_tab as (select ''||chr(10)||
                           '  '||chr(10)||
                           '   '||chr(10)||
                           '  '||chr(10)||
                           '' col1 from dual)
    -- end of mimicking your data; USE SQL below:
    select substr(col1, instr(col1, '', 1, 1) - instr(col1, 'I want to get the highest employee details and the 2nd highest employee for a particular service. But also the Department should have more than 1 employee.
    I tried the query and it gave me the correct results. But I wonder if there is another solution than to use the subquery.

    Here is the table and the query result:
    with t as
    (
    select 1 emp_id,3 mgr_id,'Rajesh' emp_name,3999 salary,677 bonus,'HR' dpt_nme from dual union
    select 2 ,3 ,'Gangz',4500,800,'Finance' from dual  union
    select 3 ,4 ,'Sid',8000,12000,'IT' from dual  union
    select 4 ,null,'Ram',5000,677,'HR' from dual  union
    select 5 ,4,'Shyam',6000,677,'IT' from dual union
    select 6 ,4 ,'Ravi',9000,12000,'IT' from dual   
    )
    select * from 
    (select emp_id, mgr_id, emp_name, dpt_nme, salary, row_number() over (partition by dpt_nme order by salary desc) rn from t where dpt_nme in 
    (select dpt_nme from t group by dpt_nme having count(*) > 1)) where rn < 3

    Hello

    You need a subquery, but you don't need more than that.
    Here's a way to eliminate the additional subquery:

    WITH     got_analytics     AS
    (
         SELECT  emp_id,     mgr_id,     emp_name, dpt_nme, salary
         ,     ROW_NUMBER () OVER ( PARTITION BY  dpt_nme
                                   ORDER BY          salary     DESC
                           )         AS rn
         ,     COUNT (*)     OVER ( PARTITION BY  dpt_nme
                                       )         AS dpt_cnt
         FROM     t
    )
    SELECT  emp_id,     mgr_id,     emp_name, dpt_nme, salary
    ,     rn
    FROM     got_analytics
    WHERE     rn     < 3
    AND     dpt_cnt     > 1
    ;
    

    Analytical functions are calculated after the clause WHERE is applied. Since we need to use the results of the analytical ROW_NUMBER function in a WHERE clause, which means that we have to calculate ROW_NUMBER in a subquery and use the results in the WHERE clause of the main query. We can call the COUNT function analytical in the same auxiliary request and use the results in the same WHERE clause of the main query.

    Would what results you if there is a link for the 2nd highest salary in some Department? For example, if you add this line to your sample data:

    select 7 ,3 ,'Sunil',8000,12000,'IT' from dual  union
    

    ? You can use RANK rather than ROW_NUMBER.

  • Help with some date functions.

    I need to write code that allows a person to, at the beginning of the year, to cancel all records that relate to the previous year.
    For example, on 05/01/11, all records for the year 2010 should be cancelled by inserting the cancellation_date as the last date of this same year.

    So I thought that the best way to proceed would be with this function:
    CREATE OR REPLACE FUNCTION TEST2
    DATE OF RETURN
    AS

    v_prior_year tank (4);
    v_last_second_string VARCHAR2 (20);
    v_last_second_date DATE;

    BEGIN

    -The year of the SYSDATE extract, convert it to a number, subtract 1, convert that year to a string.
    v_prior_year: = TO_CHAR (TO_NUMBER (TO_CHAR (SYSDATE, 'YYYY'))-1);

    -Build a string that consists of the last second of the same year.
    "v_last_second_string: = ' 31 - DEC - ' | v_prior_year | "235959 ';

    -Convert the string to a date.
    v_last_second_date: = TO_DATE (v_last_second_string, ' ' MY - DD - YYYY HH24MISS);

    RETURN v_last_second_date;

    END Test2;

    I was wondering if there is a shorter way to do this?
    Thank you.
    TUBBY_TUBBZ?select trunc(sysdate, 'YYYY') - (1/24/60/60) from dual;
    
    TRUNC(SYSDATE,'YYYY'
    --------------------
    31-DEC-2009 11 59:59
    
    1 row selected.
    
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?
    

    ?

  • Help with a case function

    Hello

    I want to create a function box where column2 is based on the value of Column1.

    For example, the table below

    On the underside, I would ask something like

    Select status, description, l3_days, (case when status = 'Open' and DEV_DAYS = null THEN L3_DAYS = 'LOGIN_DATE-SYSDATE' WHAT status = 'open' and DEV_DAYS! = NULL THEN DEV_DAYS = L3_DAYS ELSE LOGIN_DATE-L3_DAYS-SYSDATE, DEV_DAYS END)

    support.jpg

    Not sure so clearly. Basically, I want to L3_DAYS and DEV_DAYS to be updated automatically based on the login_date. I plan to add a DEV_START_DATE column, which would facilitate the calculation of DEV_DAYS

    In any case I want to know how to write a case function, where denotes Column1 Column2?

    Thank you

    There are two CASE statements like this

    select status
         , description
         , case when status = 'Open' and dev_days is null then LOGIN_DATE-SYSDATE
                else l3_days
           end l3_days
         , case when status = 'Open' and dev_days is not null then LOGIN_DATE-L3_DAYS-SYSDATE
                else dev_days
           end dev_days
    

    If this isn't what you are looking for you need to explain your best condition. Provide a CREATE TABLE script and INSERT a TABLE for examples of data and provide a few example expected output.

    Also please read Re: 2. How can I ask a question on the forums?

  • Need help with rewrite PLSQL function EVALUATE

    Hi all

    I'm trying to convert some PLSQL (from Discoverer) in a column of answers and I can't seem to get the correct formula.

    The original formula:
    MIN (Processed_Date) MORE (SCORE OF Business_Area, product, Serial_No)

    I guess that this must be done in an evaluation function, but I can't work on the correct syntax.

    This formula:
    Evaluate ('MIN (%1) OVER (PARTITION OF 2%, 3%, 4%)) ", Business_Area, Processed_Date, Serial_No, product)
    Has generated this error:
    [nQSError: 10058] A general error occurred. [nQSError: 22027] Union of incompatible types. (HY000)

    I do not know what causes the error, and tried casting explicitly throughout the column, but still getting errors.


    I am open to any suggestion.

    Thank you.

    Published by: jasonr on Dec 14, 2010 09:54

    Jasonr,

    highlighted in bold is the change
    Try this EVALUATE ('MIN (%1) OVER (PARTITION OF 2%, 3%, 4%)) AS the DATE, Processed_Date, Business_Area, product, Serial_No)
    update if it solved your problem.

    -bifacts
    http://www.obinotes.com
    J

    Published by: bifacts on December 14, 2010 21:52

Maybe you are looking for