View Full Version : Error 1034: Variables cannot be native
_forumSteve
February 8th, 2008, 12:53 PM
Hi,
I'm experiencing a problem dispatching a custom event class. A TypeError is thrown
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
The error says "Type Coercion failed: cannot convert <package name>::CustomEvent@14b7b51 to <package name>.CustomEvent."
Compile errors on LiveDocs describes the error as "variables cannot be native."
Also important to mention... It only occurs when bubbling is set to true.
Any info would be great!
Thanks!
jwopitz
February 8th, 2008, 03:54 PM
you might want to post some code. Specifically:
- the custom event class
- the point its getting dispatched
Is this in Flex or Flash. I have seen some errors likes this when you have a flex component instance firing a custom event type but the metadata tag is not the same class type.
_forumSteve
February 8th, 2008, 05:39 PM
I'm using Flash. I stripped out as much code as possible to troubleshoot this error.
The following code dispatches when a button is clicked...
package {
import flash.events.MouseEvent;
import flash.display.*;
import com.temp.CustomEvent;
public class MyWindow extends MovieClip {
public function MyWindow() {
btnOk.addEventListener(MouseEvent.CLICK, onOk);
}
public function onOk( event:MouseEvent ) {
var custom:CustomEvent = new CustomEvent("done",true);
dispatchEvent(custom);
}
}
}
The following code is the custom event...
package com.temp {
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
public class CustomEvent extends Event {
public function CustomEvent(pType:String, pBubbles:Boolean = false, pCancelable:Boolean = false) {
super(pType,pBubbles,pCancelable);
}
override public function clone():Event {
return new CustomEvent(type,bubbles,cancelable);
}
}
}
If I change my CustomEvent to a standard event, it works fine. However, I will be adding additional properties later.
So, I hope this makes sense. Here is the structure:
Window1.SWF loads Window2.SWF as a child.
Window2.SWF loads MyWindow.SWF as a child.
Window2.SWF has a listener for the CustomEvent.
MyWindow.SWF generates the CustomEvent.
If I change the parameter for the handler function in Window2 it also works fine!!!
WORKS:
function handler( e:Event ) {
Partially responsible for ERROR 1034
function handler (e:CustomEvent) {
I'm glad this is working now, but I would really like to understand the problem... Thanks!
you might want to post some code. Specifically:
- the custom event class
- the point its getting dispatched
Is this in Flex or Flash. I have seen some errors likes this when you have a flex component instance firing a custom event type but the metadata tag is not the same class type.
Felixz
February 9th, 2008, 03:40 PM
Well the custom Event u have made is just simple Event...
u could just use new Event("myAnotherEvent"). This is common misunderstending. I'm guessing that u have used reserved string for another Events
Coustom Events are used to store and pass new variables...
For example this is true Custom Event:
package loaders {
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import loaders.IClassLoaderEvent;
public class ClassLoaderProgressEvent extends ProgressEvent implements IClassLoaderEvent {
public static var LOAD_PROGRESS:String=ProgressEvent.PROGRESS;
private var _urlRequest:URLRequest;
public function ClassLoaderEvent(type:String,$urlRequest:URLReques t,$priority:int,$fails:uint,$text="",bytesLoaded:uint=0, bytesTotal:uint=0,bubbles:Boolean=false,cancelable :Boolean=false) {
super(type,bubbles,cancelable,bytesLoaded,bytesTot al);
_urlRequest=$urlRequest;
_priority=$priority;
_fails=$fails;
_text=$text;
}
public function get urlRequest():URLRequest {
return _urlRequest;
}
public function get priority():int {
return _priority;
}
public function get fails():uint {
return _fails;
}
public function get text():String {
return _text;
}
override public function clone():Event {
return new ClassLoaderEvent(type,urlRequest,priority,fails,te xt,bytesLoaded,bytesTotal,bubbles,cancelable);
}
override public function toString():String {
return formatToString("ClassLoaderEvent","type","urlRequest","priority","fails","text","bytesLoaded","bytesTotal","bubbles","cancelable","eventPhase");
}
}
}
_forumSteve
February 9th, 2008, 03:57 PM
I understand that it is identical to an event at this point. I will require adding custom properties in the near future...
Felixz
February 9th, 2008, 04:17 PM
So how is ur activation string?
dail
February 9th, 2008, 07:20 PM
Your custom event class is missing its;
public static const YOUR_CUSTOMCONSTANT:String = "yourcustomconstant";
The, when you dispatch your event, you should do it like this;
dispatchEvent(new CustomEvent(CustomEvent.YOUR_CUSTOMCONSTANT,anyPar ams));
Felixz
February 9th, 2008, 07:57 PM
Your custom event class is missing its;
public static const YOUR_CUSTOMCONSTANT:String = "yourcustomconstant";
The, when you dispatch your event, you should do it like this;
dispatchEvent(new CustomEvent("YOUR_CUSTOMCONSTANT",anyParams));
Well...
dispatchEvent(new CustomEvent(classPath.YOUR_CUSTOMCONSTANT,anyParam s));
dispatchEvent(new CustomEvent("yourcustomconstant",anyParams))
dail
February 9th, 2008, 08:24 PM
Yep.
Right you are Felixz. Fixed my mistake.
The original method I had, demonstrates the problem with using strings as event identifiers when dispatching events, a typo in the string just silently fails, where as a type when using classpath.EVENTCONSTANT will throw an error if you make a mistake.
_forumSteve
February 11th, 2008, 11:18 AM
Ok... As suggested, I just changed the dispatch so the event type string refers to a public static constant. No difference.... Still the same error.
"Type Coercion failed: cannot convert com.temp::CustomEvent@14b7b51 to com.temp.CustomEvent."
However, I think I just found the solution I'm going to use. It still makes absolutely no sense whatsoever...
So, again, here is the overall structure:
Window1.SWF loads Window2.SWF as a child.
Window2.SWF loads MyWindow.SWF as a child.
Window2.SWF has a listener for the CustomEvent.
MyWindow.SWF generates the CustomEvent.
If I declare a CustomEvent variable in the code for Window1.SWF, the error does not appear.
new Window1.SWF code:
import com.temp.CustomEvent;
var makes_no_sense:CustomEvent;
var fileLoaded:LoadFile = new LoadFile("Window2.SWF");
addChild(fileLoaded);
jwopitz
February 11th, 2008, 11:33 AM
forumSteve, you should be able to do what you are wanting to do. I use custom events all the time with no issue.
Try this and report back to us:
Change your custom event handler back to expecting a plain event as the parameter, then try to cast the event as your custom event class via:
function myFunc (e:Event):void
{
var ce:CustomEvent = CustomEvent(e);
}
If there is a problem (wtf it is, I do not know) with the dispatching of the event, then your problem might not lie in the event itself, however if it gags on the casting portion, then something small but significant is not adding up.
Put a debug break point on the function too and see if the parameter as a simple Event is not indeed a subclass.
_forumSteve
February 11th, 2008, 12:00 PM
Casting generated the same error when published from Window1.SWF.
I set a break point in the handler function, but I get "Cannot display source code at this location" I'm guessing b/c Window2.SWF has already been compiled.
_forumSteve
February 13th, 2008, 09:12 AM
If anyone is interested, I got an explanation for this error...
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=665&threadid=1336905&messid=4857652
jwopitz
February 13th, 2008, 09:22 AM
That makes alot of sense now thinking back on it. I guess I haven't encountered this issue as I do very little in the way of loading external SWFs into a Flex application. And when doing so, there is generally a Run-time Library involved.
Sorry we couldn't help you out here.
Energy Recruitm
September 8th, 2008, 01:58 AM
People! this is the Greatest Forum on the GLOOOOOOOOBE :beam:
Thank you for this sweet post ;)
unkulunkulu
September 25th, 2008, 02:00 AM
Thanks, this solved my problem as well. I didn't realize that custom events' string constants have to be unique. I was using ADDED, which apparently is also used by some other built-in event.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.