I have multiple class objects (r1, r2, r3, etc...). I am trying to access object members that are dynamically passed as variables. This is what I have...
Code:
if (this.hotS1_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
_root.desc_mc.LoadDesc("r1");
}
// desc_mc function
function LoadDesc (gridNum) {
descImg = gridNum+".descImg";
descText = gridNum+'.descText';
this.descText = descText;
this.loadDescImg (descImg);
trace(descText);
}
I get "r1.descText" from the trace command. Through the LoadDesc function, I am unable to access the class object. However, when I do 'trace(r1.descText)' it has the proper output. For some reason, it is interpreting this as an actual string.
why are you doing this? you're assigning a string to a string, and then you hope it will return the value of a method in your class.
if you use the following code it will work. The reason: Type Casting. This is what is so good in flash, you define what types are accepted and what types are returned by a function:
Code:
function LoadDesc (gridNum:MyClassName):Void {
var descImg:TypeOfdescImg = gridNum.descImg;
var descText:String = gridNum.descText;
this.descText = descText;
this.loadDescImg (descImg);
trace(descText);
}
to use the LoadDesc function, simply enter:
Code:
if (this.hotS1_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
_root.desc_mc.LoadDesc(r1);
}
if r1 is the refference to your class
i really recommend you on using typecasting. it cleans your code, and you can find problems more rapidly. Check out adobe livedocs for more info about typecasting
Hope it makes it a little clearer? if not, ask for more information,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks
One more question... when I rollover the grid, the text displays correctly. But, the image doesn't display until I rollout of the grid. Again, here is my code:
Code:
function LoadDesc (gridNum:RollOver):Void {
var descImg:String = gridNum.descImg;
var descText:String = gridNum.descText;
this.descText = descText;
this.loadDescImg (descImg);
}
function loadDescImg (descImg:String):Void {
this.descImg_mc._x = -65;
this.descImg_mc._y = -155;
this.descImg_mc.loadMovie(descImg);
}
The negative values are to have the image placed properly, when set to zero, it puts the top left corner on the registration point - which is the center of the placeholder movie clip.
you're missing a brace after the else.
but this is not what is causing the problem i think.
what does the function hitTest look like? as far as i see it should return true when the mouse is over the mc, right?
try tracing the return value of hitTest, that way you will see whether it returns false when your mouse is on top of it
Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks