I have been creating custom event for my smart loader but somehow it got some errors like “TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@dc3a251 …” and I does override clone method to avoid this error but it doesn’t help at all.
Here is code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | package com.xllusion.events { // Import class import flash.events.*; import flash.display.*; // SmartLoaderEvent public class SmartLoaderEvent extends Event { // Event constants public static const ITEM_ERROR:String = "itemError"; public static const ITEM_OPEN:String = "itemOpen"; public static const ITEM_PROGRESS:String = "itemProgress"; public static const ITEM_COMPLETE:String = "itemComplete"; public static const ITEM_INIT:String = "itemInit"; public static const ITEM_REMOVE:String = "itemRemove"; public static const ALL_COMPLETE:String = "allComplete"; // Properties public var __target:Sprite; public var __data:Object; public var __bytesLoaded:Number; public var __bytesTotal:Number; public var __percent:int; // Constructor public function SmartLoaderEvent(type:String, target:Sprite = null, data:Object = null, bytesLoaded:Number = 0, bytesTotal:Number = 0, percent:int = 0, bubbles:Boolean = false, cancelable:Boolean = false) { super(type, bubbles, cancelable); __target = target; __data = data; __bytesLoaded = bytesLoaded; __bytesTotal = bytesTotal; __percent = percent; } // Override clone() override public function clone():Event{ return new SmartLoaderEvent(type, __target, __data, __bytesLoaded, __bytesTotal, __percent, bubbles, cancelable); } } } |
After 2 hours of testing, I have found the source problem which is:
1 | public static const ALL_COMPLETE:String = "allComplete"; |
The string “allComplete” somehow causes compile error and I can not find if it is reserved by AS3 or not so I have to change it to “allCompletes” and everything works fine:
1 | public static const ALL_COMPLETE:String = "allCompletes"; |
7 users commented in " AS3 Custom Event Error #1034 Bug? "
Follow-up comment rss or Leave a TrackbackNot sure exactly what you’re trying to do, but I’ve come across this problem before. You can that conversion error when you don’t use the new statement. For example:
var blah:Blah = BlahExtender( param1 );
//THAT WILL CAUSE AN ERROR
var blah:Blah = new BlahExtender( param1 );
//THAT SHOULD WORK
You might want to rethink your logic. I’m wondering are you trying to preload a sequence of objects? Cause I think I might have a Class that might help you, if you’re interested in doing that.
the same reason why you can’t use ‘progress’ or ‘error’ these strings are already assigned to other errors fe: instead of writing
something.addEventListener(ErrorEvent.ERROR, catchError);
you could just put
something.addEventListener(“error”, catchError);
because that is the value of ErrorEvent.ERROR.
hope this helps :p
Sorry guys, I think you have missed my point here, maybe I didn’t make my point clear (Sorry, my bad~).
There is nothing wrong with the loader/event class etc…, all I was trying to say is that “allComplete” string is somehow reserved by actionscript but I cannot find it in AS document help…, if used will cause compile error.
yeah, i think that’s why they recommend you always use SmartLoaderEvent.ALL_COMPLETE instead or the string value… even in the built in events… to avoid conflicts and get better debugging info.
Thank you so much for this post. We were seeing the same error w/ a project here at work, but it was only happening when we ran the files in the Flash IDE. Your solution fixed it. We think that this bug might only be happening w/ a particular version of the player – 9.0.115.0. Is that also the version of the Flash player that you have/had at the time you saw this bug? Thank you again.
Hi Christine, yes, the bug appears on 9.0.115.0 version but I am not sure if it happens to other versions too. Glad this helps:)
I know that’s an old blog post but the answer is that “allComplete” is an undocumented event of the Flash Player.
It is actually used by Adobe’s Profiler SWF (listening to its ‘root’) to be notified when the profiled SWF has finished loading.
As this is dispatched as a basic Event type you’ll obviously get a TypeError if you expect a custom Event class.
Leave A Reply