AS3 - function passed as an argument brought bad when it is called

Hi all

I'm new to flex. I tried this: http://seancode.blogspot.com/2008/07/flex-injection-passing-function-to.html

This message essentially has a MyBox component that gets a function as an argument and calls the function on a button click.

There another component main , which has defined a function func and MyBox as a child and gives the MyBox service.

The problem is: func accesses the properties of the hand. So when he gets called it is supposed to work at hand , but in my application is running in the scope of MyBox and give a reference to property not found error.

I read that in AS2, mx.utils.Delegate was used to specify the scope in which a function must run. This has been used to define event listeners. And AS3 is supposed to do this automatically - magic closures/methods. I had no problem setting of event listeners, and they run in the correct scope...

Please tell me where I'm wrong... There is no delegate to work around this problem now. And I couldn't find anyone else facing this problem in AS3.

Thanks in advance...

Hello

The problem is that you use a function inline instead of a bound method. In this case, when you use an inline function, this function will be the scope of the caller (following the example of the appellant will be to the MyBox component) and not to the scope of the creator (hand). You can find more information about the scopes of service here: http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_21.html

If you do not need the Bindable part, you can work around the problem by using a method/function related:

(using the same example you provided)

private function backToViewZero():void {
     viewStack.selectedChild = viewZero
}

Another way (without throwing the binding mechanism) is to use the method of the function call and specify the thisArg as being the parent (main).


Tags: Flex

Similar Questions

  • That is producing this error: MuseJSAssert: error calling the function switch: Error: Invalid argument

    Website: http://lovehopemercy.org/

    In my navigation header by clicking on the option "VISIT US", that is to say generates this error: MuseJSAssert: error calling the function switch: error: invalid argument

    The other options do not work correctly. I get an error on export as HTML of MUSE, but the link works fine in other browsers. I download using Dreamweaver CC 2014. Reversal function works fine; it's the direct click of the menu item at the top that causes the problem.

    Did I miss a bad link or something that I can fix?

    Thanks in advance.

    Hello

    Could you please try some suggestions given here and see if it works for you.

    Error after update today: MuseJSAssert:Error call function argument: Error: Invalid selector

    Let me know if you have any question.

    Concerning

    Vivek

  • 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();

    }
    }

  • I have the following error on my phone design-MuseJSAssert: error calling the function switch: Error: Invalid argument

    I tried to insert the third party html code 'a noaa weather map' in the design of my phone yesterday. It did not work well. So I deleted this return. Afterwords, I get the following:

    (Message on the Web page "MuseJSAssert: error by calling the function selection: error: invalid argument.")

    I already have all the design is complete and ready to publish. The desktop version works fine. But the design of the phone does not work. For the most part, I noticed that the menu master accordion does not work now.

    Help! I really want to redo the whole phone design. Thanks, H

    I have already found and corrected the error. Apparently, when you bind a phone

    Number of muse, he is not obliged to put a colon: in the figures. I have

    have removed the colon and handed over running the program and the error is cleared

    upward. A clear tutorial on the 'phone links' would be useful.

    Thank you. H

  • Is there a way to disable the function where firefox opens a new tab when you scroll a click in the header bar?

    Is there a way to disable the function where firefox opens a new tab when you scroll a click in the header bar? This feature in conflict with my program of multiple monitors (display fusion) since this program allows you to change your current active window the monitor 1 monitor 2 and vice versa BY clicking the header of BAR SCROLLING (or whatever you call the highest part of your window). With firefox, I can't easily change my active window between monitors because instead, it opens a new tab.

    If the window is maximized, you can then switch this pref to disable the display of the tabs in the title bar:

    • browser.tabs.drawInTitlebar = false

    You can open the topic: config page via the address bar.
    You can accept the warning and click on "I'll be careful" to continue.

  • How can I remove pop ups look bad when I turn on my computer

    How can I remove pop ups look bad when I turn on my computer

    Hi Semone31,

    ·         What is the full pop-up message?

    ·         You did changes to the computer before the show?

    Follow the suggestions below for a possible solution:

    Method 1: I suggest you perform the clean boot and check.

    Place the computer in a clean boot state, then check if it helps. You can start Windows by using a minimal set of drivers and startup programs. This type of boot is known as a "clean boot". A clean boot helps eliminate software conflicts.

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

    http://support.Microsoft.com/kb/929135

     

    Note: After troubleshooting, be sure to configure the computer to start as usual as mentioned at step 7 of the article mentioned above.

    Method 2: I also suggest that you scan your computer with the Microsoft Security Scanner, which would help us to get rid of viruses, spyware and other malicious software.

    The Microsoft Security Scanner is a downloadable security tool for free which allows analysis at the application and helps remove viruses, spyware and other malware. It works with your current antivirus software.

    http://www.Microsoft.com/security/scanner/en-us/default.aspx

     

    Note: The Microsoft Safety Scanner ends 10 days after being downloaded. To restart a scan with the latest definitions of anti-malware, download and run the Microsoft Safety Scanner again.

     

    Important: During the scan of the hard drive if bad sectors are found, the scanner tries to repair this sector, all available on which data may be lost.

    Let us know if that helps.

  • Case function can be used as a parameter when calling a procedure, please advise...

    Case function can be used as a parameter when calling a procedure, please notify

    The daily procedure is called with the parameter 3 following one of the parameters using a function box between them as shown below.

    Daily_Ins (c1.p_mtrid, c1.p_UOM CASE WHEN "KWH" THEN 1 ELSIF 'KW' THEN 2 END, v_dateHold);

    In my opinion, using decode is illegal, so I think that I cannot say something like :

    Daily_Ins (c1.p_mtrid, ( decode c1.p_UOM, "KWH", 1 'KW', 2), v_dateHold);

    I think I just found something on the net

    SQL > DECLARE

    2 wages NUMBER: = 20000;

    3 employee_id NUMBER: 36325 =;

    4

    5 PROCEDURE give_bonus (emp_id in NUMBER, bonus_amt number) IS

    6 BEGIN

    7 DBMS_OUTPUT. Put_line (emp_id);

    8 DBMS_OUTPUT. Put_line (bonus_amt);

    9 END;

    10

    BEGIN 11

    12 give_bonus (employe_id,

    13 CASES

    14 salary when > = 10000 AND salary<=20000 then="">

    15. WHAT salary > 20000 AND salary<= 40000="" then="">

    16. WHAT > 40000 salary THEN 500

    17 0 OTHERWISE

    18 END);

    END 19;

    20.

    PL/SQL procedure successfully completed.

  • How to activate the search function.  I get no match found when I search for words on the scanned PDF document

    How to activate the search function.  I get no match found when I search for words on the scanned PDF document

    A scanned document is just an image; even if it contains text, it is not searchable.

    Put text in a scanned image available, you will need to perform the recognition of text (OCR), which can be made with Acrobat, but not the free player.

  • Functions: Passing parameters

    Hello

    I created a function to return a number. I'm passing the following:

    person_id NUMBER
    START_DATE DATE
    End_date DATE

    State of the service:

    WHERE person_id = person_id_in
    AND start_date between START_DATE_IN and END_DATE_IN

    I call the function in a sql statement:

    Select person_id, HC_GET_BFACTOR (p.person_id, ' 01 - apr - 2004 "," 30-apr-2004) as 'factor in Bradford.
    employees
    where start_date BETWEEN ' 01-apr-2004' AND 30-apr-2004'

    This works fine, but is there a way to avoid entering dates in the function () as above in hard. Entre clause will be used as a parameter for users to enter the start_date and end_date but how can these values be passed in the parameter without Hardcoding the HC_GET_BFACTOR (p.person_id, ' 01 - apr - 2004 "," 30-apr-2004)

    PS I will use this service in OBIEE, start_date and end_date arguments will be guests of parameters for the user to enter dates. I would like the function choose these parameter dates.

    Can anyone help?

    Thank you
  • How to do a function with the same argument multiple times and return values in the variables?

    The problem I have is that I have created a function that is really kind of database.  Basically, a bunch of:

    If (a.value == 'number') {}

    b.value = "this expression."

    }

    Inside of the shape are 2 drop-down lists that return numeric values I want to process through this function and the value of return inside separate variables.

    var a = this.getField ("OPE003. EVEN.1.MIP");

    MIP (a);

    var Result1 = Mip();

    I tried to smash * a * to treat the second field

    a = this.getField ("OPE003. EVEN.2.MIP");

    MIP (a);

    var Result2 = Mip();

    Result1 and result2 are placed in an array, joined as a string.

    In doing so, I always get the last treatment twice more than the final result.

    Can I use a function as a batch processor that way?

    You're right, I changed the code to what you said, but how to pass another value by my function so I can get Result1 and Result2?

    is it

    var a = this.getField ("OPE003. EVEN.1.MIP");

    var b = this.getField ("OPE003. EVEN.2.MIP");

    Result1 var = Mip (a);

    var Result2 = Mip (b);

    var c = new Array [performance(1), result2]

  • The writing PLSQL functions with columns as arguments (without aggregation)?

    Forum,

    . . . . Anyone know the shape / syntax of a function (Oracle10g) that works on a column (for example, SUM) without having to specify a GROUP BY clause (aggregators so defined by the user, although his end to adapt, is not quite what I'm looking for)? Web research point to a REF CURSOR argument - can I get an amen?

    . . . . I have a function that adds two objects (type = MDSYS. SDO_GEOMETRY containing geometries 'unknown' for Oracle built in functions do not work on them). To add objects K, the user must call this function time (K-1). This isn't a big problem as long as the number of adds is small (K _ < _ 5?), but what happens if the user needed to add objects N (where N + 1 is the point they go postal)? The solution seems to be to overload the existing function so that it can take a column as an argument and the user can limit the number of objects in the WHERE clause.

    See you soon,.
    Noel

    Published by: Christmas Khan on March 10, 2011 14:37 - Lavalin title of post

    Hi Noel,

    Noel Khan wrote:
    . . . . As indicated during the initial post, aggregate defined by the user are close, but require the end user to use the GROUP BY clause...

    This is not true. Aggregate functions do not require a GROUP BY clause. You have not said

    SELECT  COUNT (*)
    FROM    table_x;
    

    When you want ot know if table_x had been filled? In addition, aggreagate user-defined functions can also be called analytically.

    It would really help if you gave a concrete example of what you wanted to do.

  • JavaScript function: passing values

    Hi all

    I'm trying to call a javascript function in apex oralce to pass two variables.

    onfocus = "calTotalPrice (QUANTITY, and UNITPRICE)";

    I am calculating the price total based on the 'quantity' and 'Unit price'... but values do not happen.

    Please suggest me the correct syntax for passing values into a function.

    Kind regards
    Sandeep Reddy

    Here is a function I use to take three input fields and fill a fourth:

      function calcBMI(formItem1, formItem2, formItem3, formItem4) {
        var bmift = document.getElementById(formItem1).value;
        var bmiin = document.getElementById(formItem2).value;
        var bmiht = bmift*12 + parseInt(bmiin);
        var bmiwt = document.getElementById(formItem3).value*703;
        var bmi   = Math.round(bmiwt/(bmiht*bmiht)*100)/100;
        document.getElementById(formItem4).value = bmi;
      }
    
  • how 'this.' reference in AS3 functions?

    In the days of good old AS2, it was pretty easy to make a simple function that when mouse over:

    this.gotoAndPlay (2);

    For a lot of different buttons that I wanted to do the same thing on mouse.

    Now, with the EventListeners being at stake, which obviously doesn't work as 'this' will reference my main movie.  So, how do I, in code if I had 10 movieclips and wanted CEC to gotoAndPlay (2) on their rolling individual would do this job without writing 10 different functions named each of them individually?

    Button1.addEventListener (MouseEvent.ROLL_OVER, onOver1);

    function onOver1(event:MouseEvent):void
    {
    Button1.gotoAndPlay (2);
    }

    Button2.addEventListener (MouseEvent.ROLL_OVER, onOver2);

    function onOver2(event:MouseEvent):void
    {
    Button2.gotoAndPlay (2);
    }

    etc... that can't be good.

    "This" refers to the timeline, as it is written.  If you have written your listeners in the scenario of the (internal) button, you can use 'this' to tell them where to go (assuming that they are used as buttons from movieclips)

    this.addEventListener (MouseEvent.ROLL_OVER, onOver1);

    function onOver1(event:MouseEvent):void
    {
    this.gotoAndPlay (2);
    }

    Otherwise, if you write them in the timeline containing the buttons, then you can write all the listener/function separated at sunset (as you started earlier), or assign them all event listeners individually and have them share a function...

    Button1.addEventListener (MouseEvent.ROLL_OVER, sharedHandler);

    Button2.addEventListener (MouseEvent.ROLL_OVER, sharedHandler);

    function sharedHandler(evt:MouseEvent):void {}

    event.currentTarget.gotoAndPlay (2);

    }

    (no idea why this is indented, but I can't cancel)

  • Asked for an example of an AS3 function

    Hello

    Could someone please provide an example of a simple function, which can be accessed from any movie parent or the child. In AS2, we could use the _root.myfunction (); now it is changed, I would like to see what the procedure please.

    Thank you

    ... but you should know that the (root) timeline main is not at index 0.

    If you had to do in the main swf file:

    stage.addChildAt (new Sprite (), 0)

    then the root would be at index 1

  • How to pass a procedure argument to the script from sqlplus and run

    I would like to pass a procedure as a parameter to a file of sqlplus and run the procedure.

    The file sqlplus, test.sql, looks like:
    set serveroutput on
    set verify off
    set feedback off
    set echo off
    
    spool output.txt
    begin
      dbms_output.put_line('Start~&1'||'~'||user);
      &1;
      dbms_output.put_line('END~&1');
    end;
    /
    spool off
    A simple procedure:
    create or replace procedure proc1( p_arg in varchar2 default 'n' )
    as
    begin
      if nvl(p_arg,'n') = 'n' then
        dbms_output.put_line('Success');
      else
        dbms_output.put_line('Failed'); 
      end if;
    end proc1;
    /
    In sqlplus:
    SQL> @test.sql proc1  --This works
    SQL> @test.sql proc('x')  --This doesn't work
    SQL> @test.sql proc(''x'') --This also doesn't work
    I should be grateful if you would help or alternatives.

    Hello

    If & 1 is:

    proc ('x')
    

    then

    dbms_output.put_line('Start~&1'||'~'||user);
    

    will be passed to the compiler as

    dbms_output.put_line('Start~proc ('x')'||'~'||user);
    

    where the quote before x is interpreted as closing the quote before you begin

    It is an ideal opportunity to use Q-rating:

    dbms_output.put_line ( Q'[Start~&1~]' || user);
    

    Otherwise, use REPLACE to double apostrophes in & 1 before using it in the context of a literal string:

    dbms_output.put_line ( REPLACE ( 'Start~&1~'||user
                                   , ''''
                          , ''''''
                          )
                     );
    

Maybe you are looking for

  • iTunes 12.5 - What is boring?

    ALBUM ARTWORK Automatic resizing? Why? This happens through views, most recently added, artist and views of genres. HEART & STARS You can turn off the stars, but hearts remaining in any of the application, where the button disable? 'PLAY' BUTTON Why?

  • Windows 7 does not start after the installation of updates - sounds familiar!

    Apparently, I have another system that no longer starts after you install an update to Windows 7. New kick computer _ I have to disable the automatic update of windows. Twice I had to restore the system in the first week because he hung up after the

  • HP Pavilion TouchSmart 23-f280: No. Intermittent display problem

    Hi guys,. Need your help with this new pc HP Pavilion TouchSmart 23-f280d all-in-one desktop PC. all newly purchased this product and had no problem to display but not to start the computer. It will happen only once I used as watch videos or whatever

  • Stream flow 11: 11 cards SD - two questions

    Just bought a HP Stram SKU K3Y85UA #TBA 11. I guess that's a d011, but that does not appear on the label, it shows as AU58Y3K model number, which I cannot find in any of the manuals - maybe I'm looiing in the wrong place? In any case, I have two ques

  • SP2309W won't go into energy saving mode when connected via HDMI

    Hello I just got 2 SP2309W, and I love them, the only problem I encounter is just one of them (the one connected via HDMI) is not in power saving mode, even when I turn off my laptop. Is anyone else having the same problem? I have connected the monit