Tuesday, October 16, 2012

AdvAlert AS3 class - Download and How To Use: Part 5

In this tutorial I'll show you how to add dynamic content to alert windows.

By dynamic content I mean any object that extends DisplayObject class and can be added on stage. It can be a Sprite, a MovieClip, a Bitmap, a TextField - anything that can be visible on stage can be presented as dynamic content in windows.

You can't add dynamic content directly to a window (technically, you can, if you modify the classes), but you can add it to skins, and then apply those skins to windows.

In this example, I'll create a skin for warning windows, all of which shall have a warning icon inside.

The first step is to create a class of the content you want to embed into your windows. One way to do this is using Flash IDE - create a MovieClip with any content you want (in my case its a picture) and set its class path to a name that you will later use when referring to this class (I gave my MovieClip with the picture inside of it class path of "warning_icon").

Then you'll be able to add content to skins using AdvAlertSkin object's addContent() method. You can call it as many times as you want - there's no limit to how many objects of content you can have in your window. There are 2 parameters in the function - class name and position. Note that I said class name, not reference to a class instance.

var mySkin:AdvAlertSkin = new AdvAlertSkin();
mySkin.addContent(warning_icon, new Point(5, 40));
mySkin.textPadding = new TextPadding(5, 5, 5, 120);

AlertManager = new AdvAlertManager(this, stage, mySkin);
AlertManager.alert("Simple message!", "Title", null, 0, null, 350, 0, null, 155);



Now, each alert window created with that skin will contain content with objects of the specified class in them.

It is possible to access those objects of individual alert windows by referring to the window's content array.

Firstly, you'll need to put an alert window into a variable - this is easily done, since alert() method of AdvAlertManager returns the AdvAlertWindow instance that's created.

Using the content array, you are able to manipulate the content in any way you like:

var mySkin:AdvAlertSkin = new AdvAlertSkin();
mySkin.addContent(warning_icon, new Point(5, 40));
mySkin.textPadding = new TextPadding(5, 5, 5, 120);

AlertManager = new AdvAlertManager(this, stage, mySkin);
var myAlert:AdvAlertWindow = AlertManager.alert("Simple message!", "Title", null, 0, null, 350, 0, null, 155);
myAlert.content[0].filters = [new GlowFilter(0x000000, 0.5, 10, 10, 2, 3)];



Now I've covered all the features of AdvAlert class. Hope you find it useful!

I will give more examples of skins in the next tutorial.

Thanks for reading!

No comments:

Post a Comment