Resolvi
fazer um Cast para demonstrar a criação e utilização de um componente de Alerts
que desenvolvi e tenho usado muito nos meus projetos, alem de demonstrar como
interagir um componente com teu projeto. Resumindo, é uma biblioteca .swc que
importamos pra dentro do nosso projeto para usarmos Alerts específicos em
determinadas rotinas da aplicação...
Assista o screenCast e acompanhe o desenvolvimento.
Confira a aplicação abaixo.
Código fonte do projeto AlertaSWC:
package br.com.marcos.ui
{
import mx.controls.Alert;
public class Alerta extends Alert
{
Alert.yesLabel = "SIM";
Alert.noLabel = "NÃO";
public static const YES:uint = 0x0001;
public static const NO:uint = 0x0002;
[Embed(source="./img/alertIconOk.png")] public static var iconSucesso : Class;
[Embed(source="./img/alertIconInformacao.png")] public static var iconInformacao : Class;
[Embed(source="./img/alertIconInterrogacao.png")] public static var iconInterrogacao : Class;
public function Alerta()
{
super();
}
/**
* Normalmente usado pra mensagens de SUCESSO!
* @param msg é o texto que será exibido no Alert.
* @param Title é por padrão 'ATENÇÃO', mas pode ser passado um valor espeficíco em algum caso por parametro.
* */
public static function sucesso(msg : String, title : String = "ATENÇÃO"):void
{
Alert.show(msg, title, 0, null, null, iconSucesso, Alert.YES);
}
/**
* Normalmente usado pra mensagens de ERRO!
* @param msg é o texto que será exibido no Alert. *
* @param Title é por padrão 'ATENÇÃO', mas pode ser passado um valor espeficíco em algum caso por parametro.
* */
public static function erro(msg : String, title : String = "ATENÇÃO"):void
{
Alert.show(msg, title, 0, null, null, iconInformacao, Alert.YES);
}
/**
* Normalmente usado pra mensagens de INTERROGAÇÃO!
* @param funcao é a função que será execultada ao clicar em algum dos botões, Sim ou Não.
* @param msg é o texto que será exibido no Alert.
* @param Title é por padrão 'ATENÇÃO', mas pode ser passado um valor espeficíco em algum caso por parametro.
* */
public static function interrogacao(funcao : Function, msg : String, title : String = "ATENÇÃO"):void
{
Alert.show(msg, title, 3, null, funcao, iconInterrogacao, Alert.YES);
}
}
}
Código fonte do projeto AlertaApp:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="550" height="200" viewSourceURL="srcview/index.html">
<fx:Script>
<![CDATA[
import br.com.marcos.ui.Alerta;
import mx.controls.Alert;
import mx.events.CloseEvent;
protected function showAlertSucesso(event:MouseEvent):void
{
Alerta.sucesso("Hello World de Sucesso");
}
protected function showAlertErro(event:MouseEvent):void
{
Alerta.erro("Hello World de Erro", "OLHA O ERRO!!!");
}
protected function showAlertInterrogacao(event : CloseEvent = null):void
{
if (event == null)
{
Alerta.interrogacao(showAlertInterrogacao, "Remover registro Hello World?");
}
else if (event.detail == Alert.YES)
{
Alerta.sucesso("Registro removido com sucesso!");
}
else if (event.detail == Alert.NO)
{
Alerta.erro("Registro não pode ser removido!");
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:HGroup left="20" right="20" top="20" bottom="20" contentBackgroundAlpha="0.5"
contentBackgroundColor="#EBEBEB" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10">
<s:Panel width="145" height="80" title="Alerta de Sucesso">
<s:Button horizontalCenter="0" verticalCenter="0" toolTip="Visualiar Alert de Sucesso"
label="Visualizar" buttonMode="true"
click="showAlertSucesso(event)" />
</s:Panel>
<s:Panel width="145" height="80" title="Alerta de Erro">
<s:Button horizontalCenter="0" verticalCenter="0" toolTip="Visualiar Alert de Erro"
label="Visualizar" buttonMode="true"
click="showAlertErro(event)" />
</s:Panel>
<s:Panel width="145" height="80" title="Alerta de Interrogação">
<s:Button horizontalCenter="0" verticalCenter="0" toolTip="Visualiar Alert de Interrogação"
label="Visualizar" buttonMode="true"
click="showAlertInterrogacao()" />
</s:Panel>
</s:HGroup>
</s:Application>



