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.

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.

this.confirmListener = {
 click:function (evt) {
  trace (evt.detail);
 };
};

var Alert = mx.controls.Alert;
Alert.okLabel = "Synchronize Now";
Alert.cancelLabel = "Add New";
Alert.yesLabel = "Close";
Alert.buttonWidth = 100;

Alert.show (
 "Message",
 "Confirmation",
 Alert.OK | Alert.CANCEL | Alert.YES,
 this,
 this.confirmListener,
 "",
 Alert.OK
);


Don't like it? There are lots of published articles, pick a random one.

oCricket

Brajeshwar posted this article on Sat, Nov 8th, 2003 at 7:43 pm
Categorized under Technology and has the following tags

Prev Article: Macromedia Central

Next Article: Anna Kournikova in Mumbai


Possibly Related Articles

Archives: Visit the Archives for more articles.

Comments Post Yours

There are 4 responses so far. You can follow any responses to this entry through the RSS feed. You can skip to the end and leave a response. Pinging is currently not allowed.

  1. Andre Angelantoni November 13th, 2003 at 12:47 am 1

    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

  2. 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:)

  3. 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
    :)

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

Post yours

Sidenotes

Quick notes, scribbles, somehow related to this website and to what I do. Or perhaps I'm just plain lazy to make them into a full article.

Introduction to Adobe AIR (NetTuts)

Nettuts have a nice Introduction to Adobe AIR which focus on using HTML/JS to build an AIR Application. It covers -- Adobe AIR Architecture, How to install AIR, Get the development SDK, Configurations, gets on to ...2nd Oct, 2008

Decide Team Type from Books

What do you think of the "Team-Type" if they got these books recently? What "Team-Type" do these books suggest? ( surveys) 29th Sep, 2008

What do investors look for in a startup?

A great video Interview with Venture Hacker Naval Ravikant answering the age-old question: What do you look for in a startup? Investors look for two things that are paramount above all: # Great team: It's obvious. It's a ...27th Sep, 2008

You don't mess with the 'Englineer Bother'

(Via: Hiring Horror) 24th Sep, 2008

Dear Adobe

Do you have a gripe with the Adobe Softwares that you use? Do you have complaints about Adobe Softwares? Please visit Dear Adobe to file your informal gripe with Adobe. 15th Sep, 2008

View the Sidenotes Archive

Play the Penguin Game

Recommended

  • My Special Job My Special Job is a place where you can look for your weird necessities, strangely superb employees, when your need are more of those hackers, geeks, and ultimate rockstars in the Internet Technology.
  • o! Just Me Of colorful cultures, entertainment, media, life hacks, music, books and movies from hollywood & bollywood.
  • Not Safe for Work Ever clicked a link and felt embarrassed with the content in front of your co-workers? Ever caught unaware because the funny link your friend sent was a little beyond funny? Let’s minimize that with NSWF.
  • AS 2.0 Reference Reference for ActionScript 2.0 Programming Language used in Flash. Primarily stashed here for my own personal reference.
  • Downloads All downloads, Free and Open Source.
  • Ode to Apple Dedicated to Apple - Mac, iPhone, iPod, iTunes, Quicktime, Apple TV and all the awesome softwares for the Apple Mac.
  • Forum Oinam’s technical discussion forum where developers and designers can discuss all technical topics.

Download free Brajeshwar Wordpress Theme

Brajeshwar

Brajeshwar I firmly believe in keeping things simple, easy for users and I envison pushing the technical envelop time and again for the betterment of viable commercial and practical applications. More about me.

Brajeshwar Personal Identity Portal powered by VeriSign Labs

Brajeshwar's affinity with Adobe

My Photos

More photos on Flickr

Member of 9rules Network

Since its inception on 11th June, 2001, "Brajeshwar" has 862 Articles and 5,993 comments, contained within 20 categories and 1,229 tags.