Go Back   kirupaForum > Flash > ActionScript 3

Reply
 
Thread Tools Display Modes
Old 03-09-2010, 09:21 AM   #1
mutluturk
Registered User
Afrostyle ReferenceError: Error #1056: Cannot create property ... on flash...

Hello all,

Here is a specific problem I am facing most of the time; let me try to explain with an example.

Say I create a shape, and I want to move it with a ENTER_FRAME event, like this:

public function makeShape(){
var myShape=new Shape();
addChild(myShape);
myShape.addEventListener(Event.ENTER_FRAME,moveMyS hape);
}
public function moveMyShape (event:Event) {
event.currentTarget.x+=1;

It is cool up to here.
But what if I want to pass a variable with my shape to the event function. Say my shape has a no or a name or anything like a data; so I rewrite the code;

public function makeShape(){
var myShape=new Shape();
myShape.thisShapesNo=50;
addChild(myShape);
myShape.addEventListener(Event.ENTER_FRAME,moveMyS hape);
}
public function moveMyShape (event:Event) {
event.currentTarget.x+=1;
trace(event.currentTarget.thisShapesNo)

And now I get the error code,
"Cannot create property thisShapesNo on flash.shape.. "
OK, I understand that, but it is not fair. Anything you create with a code can have a property you want to dub or add on it, and you should call it anytime you like.
I learned that there are 2 ways to get around it, but both of them are extra work for the code, and I don't like to spend that precious memory for a cheap error like this.
First one is to add the shape as a child to a movieclip, I use this most of the time and goes like this:

public function makeShape(){
var myShape=new Shape();
var myClip=new MovieClip();
myClip.addChild(myShape);
myClip.thisShapesNo=50;
myClip.addEventListener(Event.ENTER_FRAME,moveMySh ape);
}
public function moveMyShape (event:Event) {
event.currentTarget.x+=1;
trace(event.currentTarget.thisShapesNo)

See the extra workload.. And the other way (and I've never tried) is to write your own event function where you can pass variables.. I guess something like this:

myShape.addEventListener(Event.ENTER_FRAME, moveMyShape, 50 );

So it seems like this is another extra workload for the code.
And so here is my question: How can I add a you-name-it property to any thing I've created in AS3?

Regards.
mutluturk is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?

Old 03-09-2010, 09:33 AM   #2
ven
Registered User
It is possible to add e.g. an ID reference through the name property.

For more thorough and best practice approach, you can extend the Shape Class and include e.g. a property "data" like this:

PHP Code:
public class DataShape extends Shape {
    
    public var 
data:Object;
    
    public function 
DataShape() {
        
super();
    }
    

ven is offline   Reply With Quote
Reply

Tags
1056, create, error, property, variable


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:44 AM.

SHARE:

SUPPORTERS:

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com