Current location: Hot Scripts Forums » General Web Coding » Flash & ActionScript » Class issues


Class issues

Reply
  #1 (permalink)  
Old 10-01-06, 03:56 PM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
Class issues

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.

I know it is something stupid, any ideas?
Reply With Quote
  #2 (permalink)  
Old 10-02-06, 03:56 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Code:
function LoadDesc (gridNum) {
	descImg = gridNum+".descImg";
	descText = gridNum+'.descText';
	this.descText = descText;
	this.loadDescImg (descImg);
        trace(descText);
}
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

Reply With Quote
  #3 (permalink)  
Old 10-02-06, 06:51 AM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
Thank you, I got it fixed.

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);
}
??
Reply With Quote
  #4 (permalink)  
Old 10-02-06, 08:12 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
just wondering: but aren't you displaying the image out of the range of the movieclip:
x = -65
y = -155

try setting this to 0, and see if it works then

what does the value of the descImg look like?

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 10-02-06, 01:11 PM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
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.

the following is passed into descImg:
Code:
var i1 = "8bike0.jpg";
Thanks
Reply With Quote
  #6 (permalink)  
Old 10-03-06, 03:21 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
could you post the onMouseOver code as well. i can't see any problems here, so it must be in there.

greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #7 (permalink)  
Old 10-03-06, 06:09 AM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
Code:
onClipEvent (enterFrame) {
	if (this.hotS1_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
		_root.desc_mc.LoadDesc(r1);
	}
	else if (this.hotS2_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
		_root.desc_mc.LoadDesc(r2);
	}
	else if (this.hotS3_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
		_root.desc_mc.LoadDesc(r3);
	}
	else if (this.hotS4_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
		_root.desc_mc.LoadDesc(r4);	
}
	else if (this.hotS5_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
		_root.desc_mc.LoadDesc(r5);
		}
	else if (this.hotS6_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
		_root.desc_mc.LoadDesc(r6);
}
	else 
		//_root.desc_mc.LoadDesc();
		_root.desc_mc.descText = "Rollover the bike for detailed specs...";
}
Reply With Quote
  #8 (permalink)  
Old 10-03-06, 08:12 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
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

Reply With Quote
  #9 (permalink)  
Old 10-03-06, 12:28 PM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
tracing hitTest returns true
Reply With Quote
Reply

Bookmarks


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
packaging few jar files and class into single jar file mohit Everything Java 1 09-19-06 04:15 PM
nested class constructors stealth04 Windows .NET Programming 1 06-15-06 02:47 PM
Javascript Function Class question vincentdehaan JavaScript 0 07-02-05 09:34 AM
class designs:air traffic controller system lore00 Everything Java 0 08-09-04 10:25 AM


All times are GMT -5. The time now is 06:29 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.