Skip to main content
Handycam
Known Participant
May 12, 2009
Question

Flex-like pop-up window in Flash?

  • May 12, 2009
  • 2 replies
  • 1381 views

I normally use Flex 3, and often create pop up windows using PopUpManager. However, I see no comparable way to do such a thing in Flash CS4, using AS3.

What I would like to do is create a library MovieClip element, export for Actionscript, and then call that as my "popup" window when the user clicks a button.

In Flex, I would simply call from an event handler something like:

[Bindable] private var intro:Intro;

intro = com.mycomponents.Intro(PopUpManager.createPopUp(this,com.mycomponents.Intro,true));

Where intro in the component I created to be the window.  How is something like this done in Flash, please?

This topic has been closed for replies.

2 replies

May 12, 2009

To get that sort of functionality you would create a static function of a PopupManager class that handles the creation of a Popup. So something like:

package {
    public class PopupManager {
        public static function createPopup(container:DisplayObjectContainer, content:DisplayObject) {
            var popup:Popup = new Popup();
            var popupContent:DisplayObject = new content();
            popup.addChild(popupContent);
            container.addChild(popup);
        }
    }
}

PopupManager.createPopup(stage, Intro);

Handycam
HandycamAuthor
Known Participant
May 13, 2009

Actually, this is not working.

I modified it to import the 2 missing classes:

package {

public class PopupManager {

import flash.display.DisplayObject;

import flash.display.DisplayObjectContainer;

public static function createPopup(container:DisplayObjectContainer,

content:DisplayObject) {

var popup:Popup = new Popup();

var popupContent:DisplayObject = new content();

popup.addChild(popupContent);

container.addChild(popup);

}

}

}

But I get these errors:

1046: Type was not found or was not a compile-time constant: Popup.�

1180: Call to a possibly undefined method Popup.�

1180: Call to a possibly undefined method content.�

May 13, 2009

Yeah, that was not complete code.

1046: Type was not found or was not a compile-time constant: Popup.
1180: Call to a possibly undefined method Popup.

Popup would be linked to a MovieClip in your library which has the graphical template for the popups, ie the chrome and such. You could write a custom class for it to handle more advanced stuff, like layout.

1180: Call to a possibly undefined method content

The content argument would be a reference to a DisplayObject class/subclass that you want added into the Popup as the content. That's why there's the line "popup.addContent(popupContent)" -- it's adding the popupContent into the popup. You could further position the content in the createPopup method by doing content.x = 5; content.y = 25; etc

Now to make this modal, there are various options... the easiest thing to do is just add a big semi-transparent rectangle in the back of your Popup movieclip which covers the stage. If the rectangle is converted to a MovieClip, it will by default prevent mouse events from being dispatched on objects beneath it.

Ned Murphy
Legend
May 12, 2009

I'm not sure what the pop-up aspect is that you want, and I have no experience with Flex, but if you wanted to load an item from the library then you would first assign its linkage/Class ID in the library (Intro) and then simply call upon a new instance of it...

var intro:Intro = new Intro();

intro.x = ...

intro.y = ...

addChild(intro);

If you didn't create a class file for the Intro class, Flash will automatically create it.

Handycam
HandycamAuthor
Known Participant
May 13, 2009

Thanks. What I was looking for is the behavior in Flex of modality. Is

there an easy way to mimic this?