Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-21-2007, 04:20 AM   #1
wentwj
Registered User
 
Join Date: Jun 2007
Posts: 8
Default Alert Dialog?

So I'm working on a project in Actionscript 3.0 using Flash CS3. I've come to a point where I'd really like to just quickly and easily give the user a confirmation box. In actionscript 2.0 I could do this using the Alert class in mx.controls. However it seems no similar control exists in actionscript 3.0, and any amount of googling just leads me to actionscript 2.0 references or flex references.
wentwj is offline   Reply With Quote
Old 06-21-2007, 05:37 AM   #2
plutocrat
AVM2 has mood swings. :(
 
Join Date: May 2007
Posts: 226
Default

Have a look through the help files for the new fl.* (AS3 Component) classes. There are a number of different prefabs.

That said, if I were you I would code my own general solution and put it in com.utils.dialog and then never have to make it again
plutocrat is offline   Reply With Quote
Old 06-21-2007, 05:44 AM   #3
wentwj
Registered User
 
Join Date: Jun 2007
Posts: 8
Default

Thanks for the response. I'll have to check out those classes, I think I already briefly scanned through them. I'm betting I'll have to just make my own, which ultimately is probably a good thing but... when working on a deadline it's nice to have something quick to throw in (though in all honesty had I just sat down and coded it instead of searching for a quick way online, I'd probably be done by now, lol)
wentwj is offline   Reply With Quote
Old 06-22-2007, 04:35 AM   #4
wentwj
Registered User
 
Join Date: Jun 2007
Posts: 8
Default

So in design my own version of Alert, I've run into some conceptual problems. Namely, holding the execution of other code.

Ideally what I'd like to do is create an Alert class. What I'd also like to do is be able to call a function in said class. So something along the lines of this

var alert:Alert = new Alert();
alert.alert();
trace("button clicked");

and the trace command won't execute until after the button inside the alert has been clicked. I can create the ui for the alert class, but I can't come up with a way to execute the code in this way. It seems I would need either some thread controls, or some way to execute a single line that waited for an event trigger.

Hope I made that clear enough, anyone know if anything like this is possible with actionscript? Since the actionscript 2.0 alert acted similar to this I have to think it's possible.
wentwj is offline   Reply With Quote
Old 06-22-2007, 04:54 AM   #5
TomMalufe
Salmon Eater
 
TomMalufe's Avatar
 
Join Date: Jun 2007
Location: Doylestown, PA, USA.
Posts: 740
Default

I'm not sure why you don't make the alert just a function instead of a class.
as a function it would be easy enough to just make it addChild(some dialog box) and then make an onClick removeChild(some dialog box) and then call the main function with all the real code...

basically you would give them the confirmation option and then not call the function with the continuing code until the click event.
TomMalufe is offline   Reply With Quote
Old 06-22-2007, 04:59 AM   #6
wentwj
Registered User
 
Join Date: Jun 2007
Posts: 8
Default

Making it a class or a function makes little difference to me.

But the point is I want to avoid having to divide up the code into seperate functions in order to hold the execute. It looks like thats what I'll have to do but it's a lot cleaner to write:

alert();
//code following alert()

rather than

{
alert(function);
}

function(event){
//code following alert()
}

I'm trying to make the code as readable and friendly as possible, as other people will be extending it in the future. Though I think I'll have to break down the code this way, and have already begun making the necessary changes. Just wanted to see if maybe someone more knowledgeable than I knew a way to accomplish what I wanted.
wentwj is offline   Reply With Quote
Old 06-22-2007, 06:15 AM   #7
plutocrat
AVM2 has mood swings. :(
 
Join Date: May 2007
Posts: 226
Default

To be blunt: saying, in this case "just make it a function" displays woeful ignorance of the way AS3 comes together. My knowledge of AS3 is acutely limited, however on this one, take my advice: use a class or components.

This should help get you on your way:

ActionScript Code:
package com.whatever {         //Imports     import flash.display.Shape;     import flash.display.Sprite;     import flash.geom.Rectangle;     import flash.events.MouseEvent;         //Class     public class AlertBox extends Sprite {                 //Vars         protected var box:Shape;         protected var yesBtn:Sprite;                 //Constructor         public function AlertBox($:Rectangle):void {                         //Initialise             box = new Shape()             yesBtn = new Sprite()             addChild(box)             addChild(yesBtn)                         //Render             with (box.graphics) {                 lineStyle(1)                 beginFill(0, 0.4)                 drawRect($.x, $.y, $.width, $.height)                 endFill()             }                         with (yesBtn.graphics) {                 lineStyle(1, 0x00FF00)                 beginFill(0x00FF00, 0.4)                 drawRect($.x+$.width-100, $.y$.height-40, 80, 20)                 endFill()             }                         //Events             yesBtn.addEventListener(MouseEvent.CLICK, yesClickHandler, false, 0, true)             yesBtn.addEventListener(MouseEvent.MOUSE_OVER, yesOverHandler, false, 0, true)                     }                 //Handlers         protected function yesClickHandler($):void {}         protected function yesOverHandler($):void {}     } }

Hope that helps.
plutocrat is offline   Reply With Quote
Old 06-22-2007, 07:32 AM   #8
wentwj
Registered User
 
Join Date: Jun 2007
Posts: 8
Default

Thanks a lot, thats similar to what I started to code, so I think I was going in the right direction.

Just to clarify however, that this still uses event handlers, to determine when the alert is dismissed. I've modified most of my code to work with this so I guess i've come to the realization that I can't get any kind of thread like pausing.

Thanks.
wentwj is offline   Reply With Quote
Old 06-22-2007, 07:39 AM   #9
plutocrat
AVM2 has mood swings. :(
 
Join Date: May 2007
Posts: 226
Default

Glad to help. What do you mean by 'thread pausing'?
plutocrat is offline   Reply With Quote
Old 06-22-2007, 01:09 PM   #10
wentwj
Registered User
 
Join Date: Jun 2007
Posts: 8
Default

Yeah sorry, I know it's confusing. I guess I'm referring to something along lines of multi-threading.

Since I'm using these alerts in various places throughout my code it would be nice to not have to break up the code into a pre/post alert sections in order to determine when the user clicked the alert.

For example, I have an animation that stops, asks the user a question, and once he gets the question correct a simple alert pops up, tells them they got it correct, along with any other information I want to give them. From there the animation continues. So what I'd ideal like to do is be able to go:

var alert:Alert = new Alert();
alert.notify("message");
trace("user has clicked alert");

And the last line won't execute until after the user has clicked the button inside the alert. As far as I can see now, this has to be handled by seperating any code I want to execute in the alert into a seperate function, and then passing that function into the Alert object and having the Alert object call it after the button is clicked. While this works, it would be so much cleaner if I could call a function, and execution wouldn't advance until after the alert button was clicked.

Sorry if I'm still not making sense.
wentwj is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Alert Component Problems... MMirage Components 3 03-19-2007 01:44 PM
Launch Alert from menu macsym Components 0 07-13-2004 02:32 PM
Change Alert Component Depth bubba ActionScript 2.0 0 05-11-2004 02:54 PM
customizable dialog box stefanoel ActionScript 1.0 (and below) 8 04-18-2004 10:34 PM
Open Dialog Box bbarre Other Flash General Questions 2 11-29-2001 03:11 PM


All times are GMT. The time now is 06:36 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.