ABN 25 173 915 011 markomedia - web development

markomedia - web development

  • Home
  • Contact
  • Blog

2011 August

  • markomedia
    • 2011
      • August
Share |
  • August 11, 2011

    Flash to Flex ComponentEvent coercion error solved

    Author
    Marko Tomic

    Today I had an interesting problem embedding a swf file compiled in Flash Professional CS3 into Flash Builder 4. My SWF file contained a Flash TextArea component, which dispatches a ComponentEvent when scroll bars are activated. This event resulted in the following error in Flex:

    TypeError: Error #1034: Type Coercion failed: cannot convert
    fl.events::ComponentEvent@1b06b4c1 to mx.events.FlexEvent. at
    flash.events::EventDispatcher/dispatchEventFunction() at
    flash.events::EventDispatcher/dispatchEvent() at fl.core::UIComponent/set visible() at
    fl.controls::ScrollBar/updateThumb() at fl.controls::ScrollBar/set enabled() at
    fl.controls::ScrollBar/setScrollProperties() at fl.controls::UIScrollBar/setScrollProperties()
    at fl.controls::UIScrollBar/updateScrollTargetProperties() at
    fl.controls::UIScrollBar/handleTargetChange()

    The first thing I needed to figure out was what type of ComponentEvent my TextArea was firing when scroll bar was activated. After a bit of debugging it turned out it was ComponentEvent.SHOW (weird).

    Then I wrote a little event handler in Flex that would catch this event and cast it to an object because Flex doesn’t know about ComponentEvent.

    swfLoader.addEventListener(FlexEvent.SHOW, onScroll);
    private function onScroll(event:*):void {
    event.preventDefault();
    event.stopImmediatePropagation();
    }

    That fixed it. Remember, you need to cast the event to ‘any (*)’  and call stopImmediatePropagation() method to stop Flex from processing any further event listeners.

    Cheers
    Marko

    Top

    Navigation

    • Home
    • Contact
    • Blog

    Archives

    • February 2012
    • January 2012
    • December 2011
    • November 2011
    • October 2011
    • September 2011
    • August 2011
    • July 2011
    • May 2011
    • December 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009

    From the blog

    • IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

    • opendiff and FileMerge on OS X

    • Bandwidth throttling on OS X

    • bash script useful tips

    • apr_sockaddr_info_get() failed for mydomain.com

    About us

    Marko Tomic - Web professional and an Adobe Certified Expert with over 10 years of commercial experience using variety of technologies.

    Connect

    Facebook icon Twitter icon Email icon RSS icon