• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Why am I getting this event error?

Engaged ,
Dec 08, 2009 Dec 08, 2009

Copy link to clipboard

Copied

I created a custom event to pass a parameter:

package com.events {      import flash.events.Event;            public class HotSpotEvent extends Event      {           public function HotSpotEvent(type:String,  hotSpotNumber:int=0, bubbles:Boolean=true, cancelable:Boolean=false)           {                super(type, bubbles, cancelable);                this.hotSpotNumber = 0;           }                      public static const HOT_SPOT_CLICKED:String = "hotSpotEvent";                      public var hotSpotNumber:int;                      override public function clone():Event {                return new HotSpotEvent(type, hotSpotNumber);           }      } }

Then a function in one swf is triggered and dispatches the event:

var eventObj:HotSpotEvent=new HotSpotEvent("hotSpotEvent"); eventObj.hotSpotNumber=getHotSpotNumber(obj); dispatchEvent(eventObj);

Then I have a listener on the scrollpane that loads this swf:

private function swfLoadedHandler(e:Event):void {    sp.content.addEventListener("hotSpotEvent", hotSpotHandler); }

Lastly, my event handler:

private function hotSpotHandler(e:HotSpotEvent):void {      trace("hot spot clicked = "+e.hotSpotNumber); }

Which is correctly tracing "hot spot clicked = 1" BUT also gives me:

hot spot clicked = 1

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@45b78a61 to com.events.HotSpotEvent.

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at HotSpot/clickedMe()

What did I get wrong here?

TOPICS
ActionScript

Views

516

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2009 Dec 08, 2009

Copy link to clipboard

Copied

the first line of suspect code is

 public static const HOT_SPOT_CLICKED:String = hotSpotEvent;

which should be

 public static const HOT_SPOT_CLICKED:String = "hotSpotEvent";

unless hotSpotEvent is a variable that's defined somewhere.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2009 Dec 08, 2009

Copy link to clipboard

Copied

It has the quotes, this forum removes them and apparently makes strings red.  So it's not that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2009 Dec 08, 2009

Copy link to clipboard

Copied

the next error is there's no getHotSpotNumber() method shown.  actually, there are so many problems your post can't be an accurate reflection of what you're doing.

you don't need to respond but i can't help you and i doubt anyone else can without accurate information.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2009 Dec 08, 2009

Copy link to clipboard

Copied

I didn't want to put the whole code, but there's such a method that returns an integer.

it would seem this works, since the number is correctly getting to the trace statement in the parent app.

What's odd is that the root app's event handler is firing, is correctly getting the property of the HotSpotEvent (hostSpotNumber), but then it complains about coercing the event type.

So I have attached the whole code.  The "InspectorShell.as" is the main app's document class, the inspector.as is the doc class for the movie loaded into the scrollpane, and then the custom event.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2009 Dec 08, 2009

Copy link to clipboard

Copied

LATEST

you could click file/publish settings/flash and tick "permit debugging".  that will give the line number of the error and make it easier to correct.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines