"Alert" não tem que parar a continuação do aplicativo

45 views
Skip to first unread message

André Betiolo

unread,
Sep 26, 2012, 1:39:31 PM9/26/12
to flex-...@googlegroups.com
Bom dia senhores, estou um problema, primeiro erei explicar o que quero fazer e depois se alguém tiver uma solução eu fico grato.

1- Eu tenho uma view e nela tem um botão que no evento MouseClick.CLICK vai para o seguinte procedimento.

protected function onTeste(event:MouseEvent):void{
var alerta:ReservaEscolha = new ReservaEscolha();
                                var retorno:int;
alerta.show(this,"1","2");
                                retorno = alerta.getRetorno ();
trace("Passo devia ");
}

Segue a classe ReservaEscolha:

<s:SkinnablePopUpContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
  width="100%" height="100%" creationComplete="creationComplete(event)" backgroundColor="#606060">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
public var retorno:int = 0;
[Bindable]
public var lb1:String;
[Bindable]
public var lb2:String;
public function show(pai:DisplayObjectContainer,l1:String, l2:String):void
{
this.open(pai);
lb1 = l1;
lb2 = l2;
}
protected function creationComplete(event:FlexEvent):void
{
this.width = screen.width + 10;
this.height = screen.height + 10;
this.y = (screen.height - this.height) / 2;
this.x = (screen.width - this.width) / 2 ;
border.width = screen.width - 30;
}
protected function UsarUsuario(event:MouseEvent):void
{
retorno = 1;
this.close();
}
protected function UsarOutroUsuario(event:MouseEvent):void
{
retorno = 2;
this.close();
}
public function getRetorno():int{
return retorno;
}
]]>
</fx:Script>
<s:BorderContainer id="border" backgroundColor="#71f377" horizontalCenter="0"
  verticalCenter="0">
<s:VGroup top="10" bottom="5" gap="12" horizontalAlign="contentJustify" horizontalCenter="0"
 verticalCenter="0" paddingBottom="2" paddingLeft="8" paddingRight="8" paddingTop="8">
<s:Button id="but" width="90%" height="20%" label="{lb1}" click="UsarUsuario(event)"  fontSize="14" fontStyle="normal" fontWeight="normal" horizontalCenter="0"/>
<s:Button id="but2" width="90%" height="20%" label="{lb2}" click="UsarOutroUsuario(event)"  fontSize="14" fontStyle="normal" fontWeight="normal" horizontalCenter="0"/>
</s:VGroup>
</s:BorderContainer>
</s:SkinnablePopUpContainer>

Só que na parte que destaquei em vermelho gostaria que executasse o alerta.show esperasse a pessoa escolher a opção e voltar para o onTeste(); para que junto com o getRetorno pegasse o valor corretamente, mas do modo que esta ele chama o alerta.show, só que continua executando o onTeste(), não conseguindo assim pegar o retorno corretamente.

Grato.

Eric Cavalcanti

unread,
Sep 26, 2012, 1:46:46 PM9/26/12
to flex-...@googlegroups.com
Oi Andre,

O Alert é assíncrono. Então você precisa registrar um callback para o alert.

Abs,
Eric Cavalcanti

--
-----------------------------------------------------------------------------
Você está recebendo essa mensagem por que faz parte do grupo de discussão
flex-mobile, para sair do grupo basta enviar mensagem para flex-mobile...@googlegroups.com

Vitor Yudi Hansen

unread,
Sep 26, 2012, 1:50:24 PM9/26/12
to flex-...@googlegroups.com

Ou criia um metodo, qndo o botao for selecionado e incluir ai na chamada do alert.

André Betiolo

unread,
Sep 26, 2012, 1:51:09 PM9/26/12
to flex-...@googlegroups.com
Obrigado Eric pelo o Retorno, por um acaso teria algum link de algum material ?

Obrigado :D
--
André Betiolo

Altevir Cardoso Neto

unread,
Sep 26, 2012, 2:08:44 PM9/26/12
to flex-...@googlegroups.com
Ou cria uma function pra pegar o retorno do Alert.

Exemplo:

Seu Alert:
Alert.show("Confirma ?", "Teste", Alert.YES|Alert.NO, this, tratarAlert, null);

Tratamento do retorno:
private function tratarAlert(event:CloseEvent):void{
   if(event.detail == Alert.YES){
         //executa teu método aqui;
   }
}

Att,

Altevir

André Betiolo

unread,
Sep 26, 2012, 2:18:29 PM9/26/12
to flex-...@googlegroups.com
Obrigado Altevir pela ajuda, mas é em um projeto Flex Mobile, no mesmo a classe Alert não está implementado por isso estou usando esse outro alerta, pesquisando aqui sobre os callback que o Eric falou, ele é utilizado também na classe Alert, só não achei algum exemplo bom ainda.

Altevir Cardoso Neto

unread,
Sep 26, 2012, 2:42:46 PM9/26/12
to flex-...@googlegroups.com
Da uma olhada na função callLater, eu a utilizo em projetos Flex Mobile tbém acredito que vai te ajudar, vc pode passar uma function e também parâmetros:

exemplo:

att,

Altevir

Lucas Costa

unread,
Sep 28, 2012, 9:18:29 AM9/28/12
to flex-...@googlegroups.com
Não sei se é bem isso que você precisa... em uma aplicação que desenvolvi fiz uma tela de confirmação segue o fonte... 
<s:SkinnablePopUpContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
  width="100%" height="100%" creationComplete="creationComplete(event)" skinClass="skins.AlertaSkin">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
/*---------------------------------------------------------------------------------------------------------------------------------*/
[Bindable]
public var title:String;
[Bindable]
public var message:String;
public var fOk:Function;
public var fNo:Function;
/*---------------------------------------------------------------------------------------------------------------------------------*/
public function show(message:String,title:String,owner:DisplayObjectContainer,functionOk:Function, functionNo:Function = null):void
{
this.message = message;
this.title = title;
this.open(owner,true);
fOk = functionOk;
if (functionNo != null)
fNo = functionNo;
}
/*---------------------------------------------------------------------------------------------------------------------------------*/
protected function creationComplete(event:FlexEvent):void
{
this.width = screen.width + 10;
this.height = screen.height + 10;
this.y = (screen.height - this.height) / 2;
this.x = (screen.width - this.width) / 2 ;
}
/*---------------------------------------------------------------------------------------------------------------------------------*/
protected function btOk_clickHandler(event:MouseEvent):void
{
fOk();
close();
}
/*---------------------------------------------------------------------------------------------------------------------------------*/
protected function btCancel_clickHandler(event:MouseEvent):void
{
if (fNo != null)
fNo();

close();
}
]]>
</fx:Script>
<!-- ................................................ TELA DE MENSAGENS .......................................................... -->
<s:TitleWindow width="396" close="close()" horizontalCenter="0" title="{title}"
  verticalCenter="0">
<s:VGroup horizontalAlign="center" paddingTop="8"
 paddingBottom="8" paddingLeft="8" paddingRight="8" gap="5"
 width="100%">
<s:Label fontSize="16" text="{message}"/>
<s:HGroup>
<s:Button id="btOk" width="83" height="50" label="Sim"
 click="btOk_clickHandler(event)" fontSize="16"/>
<s:Button id="btCancel" width="83" height="50" label="Não"
 click="btCancel_clickHandler(event)" fontSize="16"/>
</s:HGroup>
</s:VGroup>
</s:TitleWindow>
</s:SkinnablePopUpContainer>

Crio um objeto da classe ....e chamo passando qual a funçao que quero executar quando o usuário clica em ok...

var confirma:MyConfirmation = new MyConfirmation();
confirma.show("Deseja realizar CÓPIA do pedido n°" +pedidoVo.CODPDF.toString() + "\nValor: " + pedidoVo.TOTPDF.toString() + "?" ,"Confirmação",this,copiaPedido);
Reply all
Reply to author
Forward
0 new messages