8 Replies Latest reply on Jun 29, 2010 4:26 PM by docwisdom

    Cairngorm close and background disable

    docwisdom

      So after trying to write a custom class for TitleWindow popups for two weeks, I just couldn't invest any more time in getting them to work.

       

      So as an alternative I am using Cairngorm popup 1.7.

       

      Everything involving creating the popup works great, but I am having problems with closing.

      I dont get any compiler errors, but flash debug error pops up when I try to hit the close button on the TitleWindow.

       

      __________________________

       

       

      TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@10a9fdf9 to mx.events.CloseEvent.

      at flash.events::EventDispatcher/dispatchEventFunction()

      at flash.events::EventDispatcher/dispatchEvent()

      at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

      at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

      at flash.events::EventDispatcher/dispatchEventFunction()

      at flash.events::EventDispatcher/dispatchEvent()

      at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

      at spark.components::TitleWindow/closeButton_clickHandler()[E:\dev\4.0.0\frameworks\projects \spark\src\spark\components\TitleWindow.as:458]

      __________________________

       

       

      If I disable the error console it works just fine. Any thoughts on getting rid of this error?
      Here is the code from the popup component mxml
      __________________________

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

      <s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/mx"

         xmlns:popup="com.adobe.cairngorm.popup.*"

         title="Receive Items" x="800" y="600" width="800" height="264" close="dispatchEvent(new Event(Event.CLOSE))" textAlign="left">

      <s:layout>

      <s:VerticalLayout  horizontalAlign="center"/>

      </s:layout>

      <fx:Script>

      <![CDATA[

       

       

      ]]>

      </fx:Script>

      <fx:Declarations>

       

      <fx:Array id="category">

      <fx:String>Computers</fx:String>

      <fx:String>Phones</fx:String>

      <fx:String>Rides</fx:String>

      <fx:String>Audio</fx:String>

      <fx:String>Video</fx:String>

      </fx:Array>

       

      </fx:Declarations>

       

      <s:BorderContainer width="680" height="166" borderVisible="false">

      <s:Label text="Requested by: Someone" y="26" x="0"/>

      <s:Label text="Item: Wireless Headset" y="51" x="0"/>

      <s:Label text="Quantity Received:" y="106" x="0"/>

      <s:Label text="Order Date: 06/11/2010" y="26" x="550"/>

      <s:Label text="PO #: 378542" y="43" x="551"/>

      <s:Label text="Quantity Ordered: 1" x="0" y="77"/>

      <s:DropDownList x="105" y="100" width="43"></s:DropDownList>

      <s:CheckBox x="77" y="131"/>

      <s:Label text="Backordered:" y="136" x="0"/>

      </s:BorderContainer>

      <s:controlBarContent>

       

      <mx:Spacer width="100%" />

      <s:Button label="Save" click="dispatchEvent(new Event(Event.CLOSE))"/>

      <s:Button label="Cancel" click="dispatchEvent(new Event(Event.CLOSE))"/>

       

      </s:controlBarContent>

       

      </s:TitleWindow>

       

      __________________________

       

       

       

      Lastly, for those who are familiar with Cairngorm, is there a way to disable the background (aka main application) and have it blurred out just like the TitleWindow main function does?
      thanks!
        • 1. Re: Cairngorm close and background disable
          docwisdom Level 1

          Ok, i know the post is kinda long, but no feedback at all?

          • 2. Re: Cairngorm close and background disable
            UbuntuPenguin Level 4

            It probably has something to do with the fact that you are usnig Event.Close throughout the popup , but a close  event from a titleWindow is

            CloseEvent.Close.  So in short the problem is accurately described in the error , an Event cannot be cast to a CloseEvent.  I would try adding an event handler somewhere in the Script block so you can better see whats going on.  A function like this.

             

            <TitleWindow close="{closeHandler( event)}" .../>

             

            public function closeHandler( event:CloseEvent ):void

            {

              // do something here

            }

             

            You do know you are using your Event.Close's like CloseEvents which are dispatched and can be listened for by the same object listening for the Event.Closes.  Just a thought.

             

            If this post was helpful please mark it as such.

             

            Sincerely ,

            Ubu ,

            • 3. Re: Cairngorm close and background disable
              docwisdom Level 1

              Sorry I am a bit of a novice, so I am unfamiliar with the similarities and differences between the methods.

              I am using this code supplied by Cairngorm because when I use PopUpManager.removePopUp(this); it wont let me reuse the popup on most occasions. You can keep clicking the button, but it wont relaunch the popup.

               

              I know that I can use an event handler for the titlewindow close, but it is still a CloseEvent and I dont know what to put into the event handler that wont cause the same translation error but will ensure that cairngorm can reuse the popup.

               

              thanks!

              • 4. Re: Cairngorm close and background disable
                UbuntuPenguin Level 4

                Are you keeping a reference to your popup ?  This is how I do my popups

                 

                private var _popUp:PopUpView;

                private function getPopup():PopUpView

                {

                  if( _popUp == null )

                  {

                    _popUp = new PopUpView();

                  }

                  return _popUpView;

                }

                 

                 

                public function openPopUp( event:Event ):void

                {

                  var popUp:PopUpView = getPopUp();

                  PopUpManager.addPopUp( popUp );

                  PopUpManager.centerPopUp( popUp );

                }

                 

                But I don't use Cairngorm for anything , so you may have to look into their documentation if you can find it.


                Sincerely ,

                  Ubu

                1 person found this helpful
                • 5. Re: Cairngorm close and background disable
                  rtalton Level 4

                  <s:Button label="Cancel" click="dispatchEvent(new CloseEvent(CloseEvent.CLOSE, true, false))"/>

                  In your application, you handle the close event by adding an event listener there, NOT within the TitleWindow.

                   

                  In Flex 3, if you enable the TitleWindow's close button (showCloseButton="true"), it will automatically dispatch the CloseEvent without you having to do it manually.

                   

                  Also, if you do not call removePopUp(), the pop-up will not be destroyed.

                  1 person found this helpful
                  • 6. Re: Cairngorm close and background disable
                    docwisdom Level 1

                    1. dispatchEvent(new CloseEvent(CloseEvent.CLOSE, true, false)) reports this error

                    _____________

                     

                    Error: Error #1023: Stack overflow occurred.

                    at com.adobe.cairngorm.popup::PopUpEvent()[C:\workspaces\flex4.0betadrop17feb10\Cairngorm 3 trunk\target\checkout\libraries\Popup\src\com\adobe\cairngorm\popup\PopUpEvent.as:67]

                    at com.adobe.cairngorm.popup::PopUpBase/dispatchPopUpEvent()[C:\workspaces\flex4.0betadrop17 feb10\Cairngorm 3 trunk\target\checkout\libraries\Popup\src\com\adobe\cairngorm\popup\PopUpBase.as:362]

                    at com.adobe.cairngorm.popup::PopUpBase/closePopUp()[C:\workspaces\flex4.0betadrop17feb10\Ca irngorm 3 trunk\target\checkout\libraries\Popup\src\com\adobe\cairngorm\popup\PopUpBase.as:315]

                    at com.adobe.cairngorm.popup::PopUpBase/set open()[C:\workspaces\flex4.0betadrop17feb10\Cairngorm 3 trunk\target\checkout\libraries\Popup\src\com\adobe\cairngorm\popup\PopUpBase.as:192]

                    at com.adobe.cairngorm.popup::PopUpBase/onClose()[C:\workspaces\flex4.0betadrop17feb10\Cairn gorm 3 trunk\target\checkout\libraries\Popup\src\com\adobe\cairngorm\popup\PopUpBase.as:307]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    at components::newTicket/___newTicket_TitleWindow1_close()[/Users/brian/Documents/Adobe Flash Builder 4/PRISM/src/components/newTicket.mxml:9]

                    at flash.events::EventDispatcher/dispatchEventFunction()

                    at flash.events::EventDispatcher/dispatchEvent()

                    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]

                    ____________________

                    2. not sure how to develop the event handler within the application for the close event
                    3. I am using flex 4 and the showCloseButton property is not available for Spark TitleWindow
                    4. how would I close a window using PopUpManager without calling removePopUp? I dont see anything like PopUpManager.Close

                    thanks for everything so far!
                    • 7. Re: Cairngorm close and background disable
                      UbuntuPenguin Level 4

                      An error like that generally means you are dispatching an event in the same function where it is supposed to be handled.  Leading to an infinite loop.  Honestly , I would leave the responsibility of closing and opening a popup to a view component.  That way you can use stock AS3/Flex to solve problems that have known solutions.

                       

                      Sincerely ,

                        Ubu

                      • 8. Re: Cairngorm close and background disable
                        docwisdom Level 1

                        I originally tried using just the popupmanager but since most of my project involves a number of titlewindows I was trying to figure out how to write the minimal amount of actionscript and just pass the component name from the button and basically parse the component name in the actionscript instead of writing page after page of the same AS code just because the component name is different.

                         

                        I spent 2 weeks on the forums trying to get it figured out and couldnt. So i just downloaded Cairngorm.

                         

                        I basically have a list of components which are custom titlewindows.

                        search.mxml

                        edit.mxml

                        view.mxml

                        create.mxml

                         

                        etc.

                         

                        I want some simple AS code that will launch the component as a titlewindow when fed the component name from the button.

                         

                        <s:Button id="search" click="mypopuphandler();"/>