18
Oct
07

Using the Image control as a pop up

The following example shows how you can use the PopUpManager class to launch an modal Image control.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/18/using-the-image-control-as-a-pop-up/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        global {
            modalTransparencyBlur: 0;
            modalTransparency: 0.9;
            modalTransparencyColor: black;
            modalTransparencyDuration: 500;
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.controls.Image;
            import mx.managers.PopUpManager;

            private const IMG_PREFIX:String = "http://www.helpexamples.com/flash/images/";

            private function popIt(src:String):void {
                var img:Image = new Image();
                img.addEventListener(MouseEvent.CLICK, img_click);
                img.addEventListener(Event.COMPLETE, img_complete);
                img.load(IMG_PREFIX + src);
                img.toolTip = img.source.toString();
                PopUpManager.addPopUp(img, this, true);
            }

            private function img_complete(evt:Event):void {
                var img:Image = evt.currentTarget as Image;
                img.width = img.contentWidth;
                img.height = img.contentHeight;
                PopUpManager.centerPopUp(img);
            }

            private function img_click(evt:MouseEvent):void {
                var img:Image = evt.currentTarget as Image;
                PopUpManager.removePopUp(img);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="image 1" click="popIt('image1.jpg');" />
        <mx:Button label="image 2" click="popIt('image2.jpg');" />
        <mx:Button label="image 3" click="popIt('image3.jpg');" />
    </mx:ApplicationControlBar>

</mx:Application>

View source is enabled in the following example.


5 Responses to “Using the Image control as a pop up”


  1. 1 Jimmy Oct 18th, 2007 at 11:55 pm

    That is some really nice effect you have there! I can already think of all the stuff i can do with this.

  2. 2 knight Oct 23rd, 2007 at 12:19 pm

    is it possible to use this as a splash screen and have realtime creation progess as the alert text?

  3. 3 tiberiu Dec 3rd, 2007 at 6:47 am

    Hi,
    Really nice website with some nice begginer examples, good for the mass…

    I have a question for you. Let say you have a really big image. You want to load a resized version of that image, to speed up the loading process. You use GD library to resize the image, but you don’t want to save the result on the server, instead you want to load it directly in flex. How you do that?

    rgs, tiberiu

  4. 4 hissam May 19th, 2008 at 2:23 am

    how bout adding the image on a canvas with buttons like back,save,cancel??
    I wanna do such kinda thing, how to go about??
    Plz help, needed help urgently

  5. 5 Jesse Dec 26th, 2008 at 7:38 am

    I am looking for a way to have a mouse over effect ignore transparency in an image. I am working with a map that has odd shapes, and would like an effect to occur on mouse over, but only when within the boundary of the map, not when the mouse is over the transparent background.

    I see that the glow effect only occurs on the boundary, so I think what I need is possible with some actionscript?

    I thought for sure I would find an example here, but so far no luck in my searches. Any advise??

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed