PDA

View Full Version : Class' properties no updating...



IanC
March 1st, 2006, 03:02 AM
First off, I am a bit of a novice when it comes to Actionscript 2.0 - although I have plenty other experience with OOP programming.

Here is my situation: I have a Wheel movie clip which is linked to a Wheel class (in external .as file), and each wheel has an array of WheelPoints (also in a .as file). they are both linked similarly to their own respective MovieClip sybols in my .fla file.

Problem: I can't get up-to-date access for a property in my WheelPoints class from anywhere outside the class. I have a boolean defined for the WheelPoints class which, when traced inside the class, returns the propper value (if it is coliding or not, in this case). But when traced outside (Wheel class or in main .fla file) the original value (false) is always displayed.

Is it because the value is being set in a onEnterFrame function?

If anyone has any advice I would really appreciate it. :ne:

Thank you.

Voetsjoeba
March 1st, 2006, 03:32 AM
What is the code you're using ?

IanC
March 1st, 2006, 03:49 PM
I'll paste in the .as file who's properties I can't get at. The one in question is the "colliding:Boolean" property. I can't access it in the class that created it.

example: doing trace(wheelPoints[5].colliding) always returns false, even when a trace inside the WheelPoints class says it is colliding. (it knows it is colliding, and does update the colliding:Boolean, but only it can see the updates - no other class, or anything in the .fla file can see them.


all my own code:

///*** WheelPoint Class////////////////////////////////////////////////////////

import flash.geom.Point;

dynamic class WheelPoint extends MovieClip{
var pos:Point;
var colliding:Boolean;
var collide_with:MovieClip;
var my_Name:String;

public static function createWheelPoint (name:String, target:MovieClip,
depth:Number, collide:MovieClip,
x:Number, y:Number):WheelPoint {

var wp:WheelPoint = WheelPoint(target.attachMovie("WheelPointSymbol", name, depth));
wp.init(x,y,collide,name);
return wp;
}

public function init(x:Number, y:Number, collide:MovieClip, myName:String):Void {
pos = new Point(x,y);
my_Name = myName;
_x = pos.x;
_y = pos.y;
colliding = false;
collide_with = collide;
}

/////////////////////////////////////////////////////////////
/// onEnterFrame /////
/////////////////////////////////////////////////////////////
function onEnterFrame() {
if( collide_with.hitTest(_x,_y,true) ){
colliding = true;
//trace(my_Name+" Collided");
this.gotoAndStop(2);
}else{
colliding = false;
this.gotoAndStop(1);
}
trace("in WheelPoints="+colliding);
}



public function getColliding():Boolean {
return colliding;
}


} // end class WheelPoint


Here is where the WheelPoints are created:

function setUpPoints(num_points:Number):Void{
wheelPoints = new Array(Object);
var temp_x:Number, temp_y:Number, temp_theta:Number;
for (i=0; i<num_points; i++){
temp_theta = ((2*Math.PI)/num_points)*i;
temp_x = _x + (_width/2)*(Math.cos(temp_theta));
temp_y = _y - (_width/2)*(Math.sin(temp_theta));
var wp:WheelPoint = WheelPoint.createWheelPoint("WheelPointInstance"+i, _root, (i+3), landInstance, temp_x, temp_y );
wheelPoints[I] = wp;
}
}