Search code examples
apache-flexflash-buildermousehovershowwindow

More than one titleWindow in a Flex Application


I'm a GIS Analyst that was moved to an Analyst Programmer position. This has been a hard transition for me as I don't have much of a programming background, but I was thrown into it.

I'm working on a Flex app inside a jsp page. Essentially it is a grid 3x2 that has images and text. What I am trying to do is have more than one titleWindow reference in this page, so that when an image is clicked a titleWindow is opened. (If anyone has a better idea, especially if it has to do with a hover I am very open to that!) Currently I have it working for one image. However, when I try to add a second function it errors on me. "Error 1021: Duplicate function definition" Below is the entire code for the main page that calls up the titleWindow. The code below is what gives the Error 1021.

<?xml version="1.0" encoding="utf-8"?>

    <![CDATA[
        import flash.geom.Point;

        import mx.containers.TitleWindow;
        import mx.core.IFlexDisplayObject;
        import mx.managers.PopUpManager;

        import windows.SimplePopupWindow;   

        private var point1:Point = new Point();

        private function showWindow():void {
            var login:SimpleTitleWindowExample=SimpleTitleWindowExample(PopUpManager.createPopUp( this, SimpleTitleWindowExample , true));


            point1.x=131;
            point1.y=119;                
        point1=roadStatus.localToGlobal(point1);            
        }

        private var point2:Point = new Point();

        private function showWindow():void {
            var login:SimpleTitleWindowExampleFlood=SimpleTitleWindowExampleFlood(PopUpManager.createPopUp( this, SimpleTitleWindowExampleFlood , true));

            point2.x=289;
            point2.y=119;                
            point2=floodplain.localToGlobal(point2); 

        }           
    ]]>

</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:BorderContainer x="10" y="0" width="750" height="600" backgroundColor="#BBB082" backgroundAlpha="1.0" cornerRadius="20" borderColor="#E8DBA7">
    <s:Panel x="10" y="10" width="728" height="578" cornerRadius="20" chromeColor="#983D3A" borderColor="#F1EFE7" backgroundColor="#BBB082">
        <mx:Image x="131" y="119" width="150" height="115" source="file://GIS Map Portal/images/Map Images/SJCRoadStatus2_small.jpg" id="roadStatus" click="showWindow();"/>
        <mx:Image x="289" y="119" width="150" height="115" source="file://GIS Map Portal/images/Map Images/SJCRoadStatus_small.jpg" id="floodplain" click="showWindow();"/>
        <mx:Image x="447" y="119" width="150" height="115" source="file://GIS Map Portal/images/Map Images/SJCRoadStatus2_small.jpg"/>
        <s:Label x="131" y="242" text="SJC Road Status"/>
        <s:Label x="289" y="242" text="SJC Floodplain"/>
        <s:Label x="447" y="242" text="Assessor's Parcels"/>
        <mx:Image x="131" y="262" width="150" height="115" source="file://GIS Map Portal/images/Map Images/SJCRoadStatus_small.jpg"/>
        <mx:Image x="289" y="262" width="149" height="115" source="file://GIS Map Portal/images/Map Images/SJCRoadStatus2_small.jpg"/>
        <mx:Image x="446" y="262" width="151" height="115" source="file://GIS Map Portal/images/Map Images/SJCRoadStatus_small.jpg"/>
        <s:Label x="131" y="385" text="Label"/>
        <s:Label x="289" y="385" text="Label"/>
        <s:Label x="446" y="385" text="Label"/>
        <s:Label x="229" y="24" text="San Juan County Web Maps" fontFamily="Calvin and Hobbes" fontSize="25"/>

    </s:Panel>
</s:BorderContainer>

Below is the titleWindow code. This code works so far!

<?xml version="1.0" encoding="utf-8"?>

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

        // A reference to the TextInput control in which to put the result.
        public var loginName:Text;

        // Event handler for the OK button.
        private function returnName():void {
            //loginName.text="Name entered: " + userName.text; 
            PopUpManager.removePopUp(this);
        }
    ]]>
</mx:Script>

<mx:HBox width="323" height="147" borderColor="#E8DBA7" dropShadowVisible="true">
    <mx:Text text="The San Juan County GIS Department maintains aninteractive web map dedicated for researching county roads, but also includes city limits, lakes and rivers, and other geographic data.&#xd;" width="319" height="76" textAlign="center" color="#FFFFFF"/>
</mx:HBox>

<mx:HBox>
    <mx:Button label="Go" click="navigateToURL(new URLRequest(''), 'quote')"/>
    <mx:Button label="Back" click="PopUpManager.removePopUp(this);"/>
</mx:HBox>

Question: What code do I need to change above to be able to add more than one titleWindow (up to 6), or what code can I use for a hover to open a "window" or tool tip?

If anyone has any ideas or can direct me at all that would be great. I appreciate it!


Solution

  • Sounds like you just got thrown in the deep end. Generally speaking theres no limitation on the number of title windows you can have open, the PopUpManager class handles any UIComponent you tell it to open as a pop up and one of the arguments for the .createPopUp or addPopUp static methods on the manager will take a modal parameter which specifies if the user interaction should be blocked (indicated by blurring the application) or if the window should just be shown. It seems rather this error is stemming from your extension of the TitleWindow (the SimpleTitleWindowExample) can you post that code. Also as starting points on the topic check out the following documentation:

    General Flex:

    http://www.adobe.com/devnet/flex/videotraining.html

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html

    ^ notice the runtimes and products selection options at the top of the screen, select according to SDK you're building with (or select SDK based on features)

    PopUpManager: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/PopUpManager.html#createPopUp() http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/PopUpManager.html#addPopUp() http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/PopUpManager.html#removePopUp()

    Tooltips: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/ToolTipManager.html#createToolTip() http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/ToolTipManager.html#destroyToolTip()

    If you're still having troubles definitely post the code for the custom TitleWindow, also what version of the SDK you're using so I can try to replicate.

    EDIT: Ah okay seeing the rest of your code clears it up... you can't have two functions that have the same exact name so in your code you have showWindow as a function that is declared two times (I'm not sure how this is getting past compilation, I would have imagined the compiler would be smart enough to see this error before run-time, but it is what it is). Change the other showWindow to be something like showOtherWindow or something along those lines. It also looks like you come from a procedural programming background (C or some other non-OOP language) Object Oriented programming takes a little while to get your head around but makes a whole lot more sense when it comes to solving real world problems once you understand it, basically you're setting up descriptions and sending messages between objects using method calls and when you define a class, via AS or MXML you're defining the methods (order of method/property definitions doesn't functionally matter, things are still procedural, like step by step within the methods but the order of method declaration or property declaration has no effect).

    This may be helpful: http://www.codeproject.com/KB/architecture/OOP_Concepts_and_manymore.aspx

    I'm basically at the opposite end of the spectrum in terms of skills, I have a formal education from DePaul University in computer science but at my current position am doing a lot of google maps flash code so I'm finding myself more and more needing to understand Datums and other GIS specialty info (just thought it was sort of interesting to find someone at the same intersection but going the other way :).