package
{
import mx.core.Application;
import mx.containers.TitleWindow;
import mx.events.FlexEvent;
import mx.events.ResizeEvent;
/**
* a class that handles centering itself in the entire application window,
* does a center when the swf is resized, or when you call <code>selfCenter</code>
* from one of it's subclassed implementations
*/
public class SelfCenteringTitleWindowPopUp extends TitleWindow
{
/**
* constructor
*/
public function SelfCenteringTitleWindowPopUp()
{
super();
addEventListener( FlexEvent.CREATION_COMPLETE, handleCreationComplete );
}
/**
* when the creation of the TitleWindow is complete, add listener for resize events
* @param fe
*/
protected function handleCreationComplete( fe:FlexEvent ):void
{
Application.application.addEventListener( ResizeEvent.RESIZE, selfCenterFromResize );
}
/**
* the resize event handler method, uses <code>selfCenter</code>
* @param re
*/
protected function selfCenterFromResize( re:ResizeEvent ):void
{
selfCenter();
}
/**
* the method that does the centering of this popup
*/
protected function selfCenter():void
{
x = ( Application.application.width - width ) / 2;
y = ( Application.application.height - height ) / 2;
}
}
}
MXML:::
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" creationComplete="initApp()">
<mx:Script>
import Startup;
private function initApp():void
{
var st:Startup = new Startup();
}
</mx:Script>
</mx:Application>
Startup.as:::
package
{
import mx.managers.PopUpManager;
import mx.containers.Canvas;
import AddSubscriptionModal;
public class Startup
{
public function Startup()
{
var cn:Canvas = new Canvas();
Application.application.addChild( cn );
var asm:AddSubscriptionModal = PopUpManager.createPopUp( cn, AddSubscriptionModal, true ) as AddSubscriptionModal;
}
}
}
AddSubscriptionModal.as:::
package
{
import mx.managers.PopUpManager;
import mx.events.CloseEvent;
import SelfCenteringTitleWindowPopUp;
public class AddSubscriptionModal extends SelfCenteringTitleWindowPopUp
{
public function AddSubscriptionModal()
{
doInit();
addEventListener( CloseEvent.CLOSE , handleCloseModal );
}
private function doInit():void
{
title = "test";
showCloseButton = true;
width = 400;
height = 200;
selfCenter();
}
private function handleCloseModal( ce:CloseEvent ):void
{
PopUpManager.removePopUp( this );
}
}
}
I appreciate your help though..
smith
On 9/18/06, Tim Hoff <[EMAIL PROTECTED]> wrote:
Perhaps it's because you are using AS to create the canvas.
Possibly a race condition (asynchronous) is occurring as the canvas
is resized and the popup is centered. You could always just use
mx:Canvas in your main application class instead. It all gets
turned into AS anyway. Sorry that I couldn't be of more help
-TH
--- In flexcoders@yahoogroups.com, "aaron smith"
<[EMAIL PROTECTED]> wrote:
>> doesnt seem to work correctly. It actually puts the popup in the
negative
> window space. (see attachment)
> I wonder why it would do that. is it something to do with canvas /
> percentWidth / percentHeight. i've event tried commenting that out
and it
> still only puts it at 0,0.
>
>
>
>
>
>
>
>
>
>
>> On 9/18/06, Tim Hoff <[EMAIL PROTECTED]> wrote:
> >
> > Hi Aaron,
> >
> > This code will center the popup relative to the popups's parent.
In
> > your case "cn".
> >
> > PopUpManager.centerPopUp(asm);
> >
> > -TH
> >
> > smith"
> >
> > <beingthexemplarylists@> wrote:
> > >
> > > I'm trying to understand the popup manager better, i created a
> > quick test
> > > just to get it working and test it out.. most works fine but
> > having problems
> > > understanding how to center the popup..
> > >
> > > here is my code:
> > >
> > >
> > > MXML:::
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> > > layout="horizontal" creationComplete="initApp()">
> > > <mx:Script>
> > > import Startup;
> > >
> > > private function initApp():void
> > > {
> > > var st:Startup = new Startup();
> > > }
> > > </mx:Script>
> > > </mx:Application>
> > >
> > >
> > > Startup.as:::
> > >
> > > package
> > > {
> > >
> > > import mx.managers.PopUpManager;
> > > import mx.containers.Canvas;
> > > import mx.core.Application;
> > > import mx.containers.TitleWindow;
> > > import AddSubscriptionModal;
> > >
> > > public class Startup
> > > {
> > > public function Startup()
> > > {
> > > var cn:Canvas = new Canvas();
> > > cn.percentWidth = 100;
> > > cn.percentHeight = 100;
> > >
> > > Application.application.addChild( cn );
> > >
> > > var asm:AddSubscriptionModal = PopUpManager.createPopUp
> > ( cn,
> > > AddSubscriptionModal, true ) as AddSubscriptionModal;
> > > }
> > > }
> > > }
> > >
> > >
> > > AddSubscriptionModal.as:::
> > >
> > > package
> > > {
> > >
> > > import mx.containers.TitleWindow;
> > > import mx.managers.PopUpManager;
> > > import mx.events.CloseEvent;
> > >
> > > public class AddSubscriptionModal extends TitleWindow
> > > {
> > > public function AddSubscriptionModal()
> > > {
> > > doInit();
> > > addEventListener( CloseEvent.CLOSE, handleCloseModal );
> > > }
> > >
> > > private function doInit():void
> > > {
> > > title = "test";
> > > showCloseButton = true;
> > > width = 400;
> > > height = 200;
> > > //PopUpManager.centerPopUp( this ); //this causes an
> > run-time
> > > error, not sure why??
> > > }
> > >
> > > private function handleCloseModal( ce:CloseEvent ):void
> > > {
> > > PopUpManager.removePopUp( this );
> > > }
> > > }
> > > }
> > >
> > >
> > >
> > > I am wondering if giving the createPopUp method the canvas as
> > parent is the
> > > problem?
> > >
> > > can someone glance at this quick and see if you can help? or
does
> > someone
> > > have an example already?
> > >
> > > thanks all!
> > >
> > > smith
> > >
> >
> >
> >
>
__._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
Software development tool Software development Software development services Home design software Software development company
Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
__,_._,___
- [flexcoders] Re: PopUpManager quick help Tim Hoff
- Re: [flexcoders] Re: PopUpManager quick help aaron smith
- [flexcoders] Re: PopUpManager quick help Tim Hoff
- Re: [flexcoders] Re: PopUpManager quick help aaron smith
Reply via email to