acho que encontrei a solução ;)
corrijam-me se existir outra forma mais simples :
package CentralPackage.BasicControls
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.core.IFlexModule;
import mx.core.IFlexModuleFactory;
import mx.core.UIComponent;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.managers.ISystemManager;
import mx.managers.PopUpManager;
/**
* MyAlert
*
* @see mx.controls.Alert
*
* @author Ricardo Araujo
*/
public class MyAlert extends Alert
{
private var isDragging : Boolean = false;
/**
* MyAlert
*
* @param _text : String = ""
* @param _title : String = ""
* @param _flags : uint = 0x4 - Alert.OK
* @param _parent : Sprite = null
* @param _closeHandler : Function = null
* @param _iconClass : Class = null
* @param _defaultButtonFlag : uint = 0x4 - Alert.OK
* @param _moduleFactory : IFlexModuleFactory = null
*
* @author Ricardo Araujo
*/
public function MyAlert(_text : String = "", _title : String =
"",
_flags : uint = 0x4 /* Alert.OK */, _parent : Sprite = null,
_closeHandler : Function = null, _iconClass : Class = null,
_defaultButtonFlag : uint = 0x4 /* Alert.OK */, _moduleFactory :
IFlexModuleFactory = null)
{
super();
var modal : Boolean = (_flags & Alert.NONMODAL) ? false
: true;
if (!_parent)
{
var sm : ISystemManager =
ISystemManager(FlexGlobals.topLevelApplication.systemManager);
// no types so no dependencies
var mp : Object =
sm.getImplementation("mx.managers.IMarshallPlanSystemManager");
if (mp && mp.useSWFBridge())
{
_parent = Sprite(sm.getSandboxRoot());
}
else
{
_parent =
Sprite(FlexGlobals.topLevelApplication);
}
}
if (_flags & Alert.OK || _flags & Alert.CANCEL ||
_flags &
Alert.YES || _flags & Alert.NO)
{
buttonFlags = _flags;
}
if (_defaultButtonFlag == Alert.OK ||
_defaultButtonFlag ==
Alert.CANCEL || _defaultButtonFlag == Alert.YES || _defaultButtonFlag
== Alert.NO)
{
defaultButtonFlag = _defaultButtonFlag;
}
text = _text;
title = _title;
iconClass = _iconClass;
if (_closeHandler != null)
{
addEventListener(CloseEvent.CLOSE,
_closeHandler);
}
// Setting a module factory allows the correct embedded
font to be
found.
if (_moduleFactory)
{
moduleFactory = _moduleFactory;
}
else if (_parent is IFlexModule)
{
moduleFactory =
IFlexModule(_parent).moduleFactory;
}
else
{
if (_parent is IFlexModuleFactory)
{
moduleFactory =
IFlexModuleFactory(parent);
}
else
{
moduleFactory =
FlexGlobals.topLevelApplication.moduleFactory;
}
// also set document if parent isn't a
UIComponent
if (!_parent is UIComponent)
{
document =
FlexGlobals.topLevelApplication.document;
}
}
this.addEventListener(FlexEvent.CREATION_COMPLETE,
creationComplete_handler);
PopUpManager.addPopUp(this, _parent, modal);
}
/**
* creationComplete_handler
*
* @param event : FlexEvent
*
* @author Ricardo Araujo
* */
private function creationComplete_handler(event : FlexEvent) :
void
{
this.removeEventListener(FlexEvent.CREATION_COMPLETE,
creationComplete_handler);
this.setActualSize(this.getExplicitOrMeasuredWidth(),
this.getExplicitOrMeasuredHeight());
PopUpManager.centerPopUp(this);
isPopUp = false;
this.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,
MouseDown_handler);
this.titleBar.addEventListener(MouseEvent.MOUSE_UP,
MouseUp_handler);
this.titleBar.addEventListener(MouseEvent.MOUSE_MOVE,
MouseMove_handler);
this.titleBar.addEventListener(MouseEvent.ROLL_OUT,
MouseUp_handler);
}
/**
* MouseDown_handler
*
* @param event : MouseEvent
*
* @author Ricardo Araujo
* */
private function MouseDown_handler(event : MouseEvent) : void
{
this.startDrag();
isDragging = true;
}
/**
* MouseMove_handler
*
* @param event : MouseEvent
*
* @author Ricardo Araujo
* */
private function MouseMove_handler(event : MouseEvent) : void
{
if (isDragging)
{
var applicationWidth : Number =
FlexGlobals.topLevelApplication.width;
var applicationHeight : Number =
FlexGlobals.topLevelApplication.height;
if (x + width > applicationWidth)
{
x = applicationWidth - width;
}
else if (x < 0)
{
x = 0;
}
if (y + height > applicationHeight)
{
y = applicationHeight - height;
}
else if (y < 0)
{
y = 0;
}
}
}
/**
* MouseUp_handler
*
* @param event : MouseEvent
*
* @author Ricardo Araujo
* */
private function MouseUp_handler(event : MouseEvent) : void
{
this.stopDrag();
isDragging = false;
}
}
}
On 16 Mar, 14:50, João Saleiro <[email protected]> wrote:
> Boas,
>
> julgo que n�o ser� assim t�o f�cil. Teria mesmo que investigar a fundo
> para conseguir arranjar um workaround. No fundo, precisas de encontrar
> no c�digo do Alert o local onde � chamado o startDrag, e � essa a
> func�o
> que tens que fazer override.
>
> No entanto, sugerir-te-ia que criasses o teu pr�prio componente de Alert
> que replica o funcionamento do Alert. Vai-te dar um bocadinho mais de
> trabalho no in�cio, mas no futuro ter�s mais controlo sobre o seu
> comportamento. Isto, se o extend ao Alert der demasiada dor de cabeca...
>
> linkedIn <http://pt.linkedin.com/in/jsaleiro> Jo�o Saleiro
> Chief Technology Officer
> Tel: 00351 916 077 097
> Email: [email protected] <mailto:[email protected]>
> Skype: joao.saleiro <callto://pedro.arelo>
>
> Webfuel Solutions <http://www.webfuel.pt> www.webfuel.pt
> <http://www.webfuel.pt>
> Lisbon, Portugal
>
> On 16-03-2011 10:42, j42z wrote:
>
>
>
>
>
>
>
> > alguma dica?
> > o que pretendo mesmo � limitar o drag de um alert ao extremos
> > superior, inferior, direita e esquerda do ecr�.
> > j� experimentei chamar o show( dentro do construtor... funciona, mas
> > nunca cai no updateDisplayList
>
> > On 15 Mar, 18:20, j42z<[email protected]> wrote:
> >> Boas,
>
> >> estou aqui a tentar estender da Alert para poder adicionar aquelas
> >> limita��es de drag ao utilizador, mas n�o consigo depois chamar este
> >> componente... e tamb�m n�o consigo fazer override do show() nem do
> >> okLabel
> >> Fiz isto para um componente estendido do TitleWindow e resultou
>
> >> package CentralPackage.BasicControls
> >> {
> >> import mx.controls.Alert;
> >> import mx.core.FlexGlobals;
>
> >> public class MyAlert extends Alert
> >> {
> >> public function MyAlert()
> >> {
> >> super();
> >> }
>
> >> override protected function
> >> updateDisplayList(unscaledWidth:Number,
> >> unscaledHeight:Number):void
> >> {
> >> super.updateDisplayList(unscaledWidth,
> >> unscaledHeight);
>
> >> var applicationWidth : Number =
> >> FlexGlobals.topLevelApplication.width;
> >> var applicationHeight : Number =
> >> FlexGlobals.topLevelApplication.height;
>
> >> if (x + width> applicationWidth)
> >> {
> >> x = applicationWidth - width;
> >> }
> >> else if (x< 0)
> >> {
> >> x = 0;
> >> }
>
> >> if (y + height> applicationHeight)
> >> {
> >> y = applicationHeight - height;
> >> }
> >> else if (y< 0)
> >> {
> >> y = 0;
> >> }
> >> }
> >> }
>
> >> }
--
Recebeu esta mensagem porque está inscrito no grupo "Mailing List da Comunidade
Portuguesa de Rich Internet Applications - www.riapt.org" dos Grupos do Google.
Para publicar uma mensagem neste grupo, envie um e-mail para
[email protected].
Para anular a inscrição neste grupo, envie um e-mail para
[email protected].
Para ver mais opções, visite este grupo em
http://groups.google.com/group/riapt?hl=pt-PT.