Alert Component, handling event in a better way

Something around the mid September, there was a post on using Alert Component for Flash MX 2004 Pro.

There had been a project (classified as of now) here where Alert Component was commissioned to be used for all Alerts (that is what they are for). Then couple of issues arose, of which, I am not sure if people have already known that, solved through a better way or have better ways of handling the issue. Like the examples in the doc and like the one in the recent post for the Alert component, a need arises to do something similar but from nested classes. If the function reference are specified like a normal callback, the scope in which the function is called becomes undefined. The need was to pass the handler object and the string callback function, so that callback is in the correct scope.

Well, according to the example in the docs the clickHandler is a function reference. But if you pass a function reference as a argument, the scope with which the function is called is not going to be what you need. To get around to this, a listener object which had a click method was used, instead of the function reference and it worked; found the tip in the Using Component Events tree. Now, should we say that the docs are wrong on this. You have to pass a listener object that is either handling the event the DOM way or listen to the event the new dispatcher way.

  • Andre Angelantoni

    Hi, I tried your solution to using an alert within a class, but with no luck. The syntax checker comes back with "There is no property with the name 'confirmListener'".

    The code is within a method of a form class, so it suffers from the scope issue you discuss above.

    Here is the code:

    private function isOptionsValid():Boolean {
    var isValid = false;
    var confirmListener:Function = null;
    var messageStr:String = null;

    Alert.okLabel = "YES!!!";

    confirmListener = {
    click: function (evt) {
    trace (evt.detail + "was clicked");
    }
    };

    if (2 > 1) {
    messageStr = "The number of Open File licenses is greater than the sum of servers and clients. Is this OK?";
    Alert.show(messageStr, "Confirm Open File Licenses", Alert.YES | Alert.NO, this, confirmListener, null, Alert.OK);
    }
    return true;
    }

    Have you successfully used the method you described from within a class?

    Thanks for your great site
    Andre

  • Andre Angelantoni

    Hi, I tried your solution to using an alert within a class, but with no luck. The syntax checker comes back with "There is no property with the name 'confirmListener'".

    The code is within a method of a form class, so it suffers from the scope issue you discuss above.

    Here is the code:

    private function isOptionsValid():Boolean {
    var isValid = false;
    var confirmListener:Function = null;
    var messageStr:String = null;

    Alert.okLabel = "YES!!!";

    confirmListener = {
    click: function (evt) {
    trace (evt.detail + "was clicked");
    }
    };

    if (2 > 1) {
    messageStr = "The number of Open File licenses is greater than the sum of servers and clients. Is this OK?";
    Alert.show(messageStr, "Confirm Open File Licenses", Alert.YES | Alert.NO, this, confirmListener, null, Alert.OK);
    }
    return true;
    }

    Have you successfully used the method you described from within a class?

    Thanks for your great site
    Andre

  • http://www.kredit-ohne-schufa-auskunft.de Kredit

    I agree with your main topics. But if youz need
    some solution for your financial problems.
    You may have a look f?r my site. Offering
    Kredit ohne Schufa and further on
    Kredit online  im
    combination with online tips.
    You can also choose between
    Kredite and schufafreie
    Kredite. Meanwhile you can look at
    Kredit ohne Schufa and
    fulfill the
    formular at Kredit schufafrei
    and Kredit ohne Schufa.

    greetings from germany
    o:)

  • http://www.kredit-ohne-schufa-auskunft.de Kredit

    I agree with your main topics. But if youz need
    some solution for your financial problems.
    You may have a look f?r my site. Offering
    Kredit ohne Schufa and further on
    Kredit online  im
    combination with online tips.
    You can also choose between
    Kredite and schufafreie
    Kredite. Meanwhile you can look at
    Kredit ohne Schufa and
    fulfill the
    formular at Kredit schufafrei
    and Kredit ohne Schufa.

    greetings from germany
    o:)

  • http://www.kredit1x1.de Kredit

    I agree with your points of views. Bur if want to
    solve financial problems look at kredit ohne
    schufa, going on with
    kredite and
    schufafreie kredite.
    More informations about judgement at kredit tips. 
    Looking at kredit and
    kredit schufafrei and
    kredit online
    you find final informations.
    greetings from germany
    :)

  • http://www.kredit1x1.de Kredit

    I agree with your points of views. Bur if want to
    solve financial problems look at kredit ohne
    schufa, going on with
    kredite and
    schufafreie kredite.
    More informations about judgement at kredit tips. 
    Looking at kredit and
    kredit schufafrei and
    kredit online
    you find final informations.
    greetings from germany
    :)

  • http://www.adacto.it Alessio Prosperi

    The correct code to use Alert Component is:

    import mx.controls.Alert;

    class test{
    private var myAttr:String;

    public function test(){
    myAttr = "This is a test";
    }
    public function click(evt){
    trace(evt.detail + " in class: " + myAttr);
    }

    public function foo(){
    Alert.show("Message", "Confirmation", Alert.OK | Alert.CANCEL | Alert.YES, null, this, "", Alert.OK);
    }
    }

    I hope it has been usefull!
    Bye

  • http://www.adacto.it Alessio Prosperi

    The correct code to use Alert Component is:

    import mx.controls.Alert;

    class test{
    private var myAttr:String;

    public function test(){
    myAttr = "This is a test";
    }
    public function click(evt){
    trace(evt.detail + " in class: " + myAttr);
    }

    public function foo(){
    Alert.show("Message", "Confirmation", Alert.OK | Alert.CANCEL | Alert.YES, null, this, "", Alert.OK);
    }
    }

    I hope it has been usefull!
    Bye