Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-05-2005, 10:49 AM   #1
glantucan
newbe forever!
 
glantucan's Avatar
 
Join Date: Oct 2004
Location: Madrid, Spain
Posts: 88
Default problem accesing instance properties defined in a class

Hello all,
I'm writing some classes to simulate 3d movement of MCs.
I took and old class I made to simulate the same with letters. It was a class which extended the MovieClip class.
Now I decided to make it more general and made it a standalone class wich creates a movieclip that I can fill from outside usin public methods.
The problem is that I cant access the _r (3d position) or any other property from inside an onEnterFrame attached to the movieclip which contains the 3d MC

This is the code for a random movement method of the class:
ActionScript Code:
public function triniRandomMove(){                 var i : Number;         var a_mod : Number = 0.7;         var v_mod : Number = 1.0;         var r_max : Array = [_boxWidth, _boxHeight,_boxDepth];         for (i=0;i<=2;i++){             _r[i] = Math.random()*r_max[i];             _v[i] = (Math.random()*2 - 1)*v_mod;         }         target_mc.onEnterFrame = function(){             for (i=0;i<=2;i++){                 _a[i] = (Math.random()*2 - 1)*a_mod;             }                         trace(_a);             mruaMove_frame();             checkBoundaries();             set3dPosition();         }     }

Where _r, _v, and _a are private properties of the class. The trace(_a); only spits 'undefined'.
Any idea of what's the solution?
Glantucan
glantucan is offline   Reply With Quote
Old 05-05-2005, 11:02 AM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

onEnterFrame is called in the scope of the target_mc movie clip, not the class. Because of that, _a is assumed to be in the target_mc, which its not, so it results in an undefined. You need to handle that change of scope somehow. The following provides ways of doing that:
http://www.kirupa.com/web/xml/XMLspecificIssues3.htm
__________________
(6)
senocular is offline   Reply With Quote
Old 05-05-2005, 12:05 PM   #3
glantucan
newbe forever!
 
glantucan's Avatar
 
Join Date: Oct 2004
Location: Madrid, Spain
Posts: 88
Default

Yes, I understand (I think)
I changed it using solution 3.1, so tha I had to change also the method calls:
ActionScript Code:
var host = this; target_mc.onEnterFrame = function(){                 for (i=0;i<=2;i++){                        host. _a[i] = (Math.random()*2 - 1)*a_mod;                 }                 trace(host._a);                 host.mruaMove_frame();                 host.checkBoundaries();                 host.set3dPosition();         }

But I still have a problem, don't know if related with this. When I create several instances with different pictures, only the last one moves, the others stay in rest in the place where they were created.
Any clue?

And another question. Wouldn't be better to create a onEnterFrame method for the class which moves the container_mc. I wouldn't have the same problem, right? Because in such case the onEnterFrame would be within the scope of the class.

Thanks a lot
Glantucan
glantucan is offline   Reply With Quote
Old 05-06-2005, 01:54 PM   #4
glantucan
newbe forever!
 
glantucan's Avatar
 
Join Date: Oct 2004
Location: Madrid, Spain
Posts: 88
Default

Hello again
I solved the problem, it was a mistake in another part of the code, and was not related with this.

But I was playing a little with the idea of creatig my own onEnterFrame for the class. I tried this:
ActionScript Code:
class mc3d extends MovieClip{                   ...         public function onEnterFrame():Void{         super.onEnterFrame();         trace("Hello every frame");     } }

But didn't get the trace messages after compiling?

Any idea?
Thanks
Glantucan
glantucan is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:45 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.