Variable Scope Question - Please Help

I am attempting to build a flash application that dynamically attaches movies to the main page based on read in information. I am having difficulties accessing the movies / variables of the class via methods that are written. When I run this in debug mode, I am able to see the _level0.homeTeam1 variables within this object, but cannot access it at the gameClass.prototype.OnRollover level? The rollover is called, because my trace statement executes, but when I attempt to access the variables of the object it only shows my initially hardcoded variables in the class.

Please let me know where I am going wrong with this code. Thank you in advance for your help with this, been up for days trying to get it to work :frowning:

gameCount = 3;
mHomeTeam1 = "gbhome";
mVisitorTeam1 = "car";
mHomeTeam2 = "bufhome";
mVisitorTeam2 = "arz";
mHomeTeam3 = "carhome";
mVisitorTeam3 = "buf";

gameClass = function(teamnum,sel,gamenum,visitorhome){
	this.teamnum = 10;
	this.sel = false;
	this.gamenum = 1;
	this.visitorhome = "visitorhome";
}

gameClass.prototype = new MovieClip();

for (var i = 1; i<=gameCount; i++) {
    Object.registerClass(["mHomeTeam"+i], gameClass);
    ["homeTeam"+i].attachMovie(["mHomeTeam"+i],"homeTeam"+i,i-10);
	["homeTeam"+i].sel=false;
	["homeTeam"+i].gamenum=i;
	["homeTeam"+i].visitorhome="home";
	
    Object.registerClass(this["mVisitorTeam"+i], gameClass);
    this["visitorTeam"+i].attachMovie(this["mVisitorTeam"+i], this["visitorTeam"+i],i-270);
	this["visitorTeam"+i].sel=false;
	this["visitorTeam"+i].gamenum=i;
	this["visitorTeam"+i].visitorhome="visitor";
}



GameClass.prototype.setSelection = function(sel) {
   trace("set selection called");
   this.sel = sel;
};

GameClass.prototype.setGameNum = function(gamenum) {
   this.gamenum = gamenum;
};

GameClass.prototype.getGameNum = function() {
   return this.gamenum;
};

GameClass.prototype.setVisitorHome = function(vh) {
   this.visitorhome= vh;
};

GameClass.prototype.setTeamNum = function(num) {
   this.teamnum = num;
};

gameClass.prototype.onRollOver = function() {
	if(this.sel == false){
    	this.gotoAndStop(2);
	}
}
gameClass.prototype.onRollOut = function() {
	if(this.sel == false){
    	this.gotoAndStop(1);
	}
}

gameClass.prototype.onPress = function(){
	trace("game num is :"+this.gamenum);
	trace("visitorhome is :"+this.visitorhome);
	if (this.sel == false){
		this.sel = true;
		this.gotoAndPlay(3);
		
	}else{
		this.sel = false;
		this.gotoAndStop(1);
	}
}

IMO you’re not registering the clip as a membre of the class correctly. Do it only once, and use the linkage name you gave to your clip, not the name you give when you attach it. Something like

Object.registerClass("mVisitorTeam", gameClass);

pom :elderly:

Oh, and I took the liberty of editing your post for better visibility.

the mHomeTeam and mVisitorTeam variables are multiple clips. that I would like to be used as a class and have their own variables so I check the state of each.

In the top of my code I hardcoded some of the variables… but these will eventually be read into from a database.

gameCount = 3;
mHomeTeam1 = “gbhome”;
mVisitorTeam1 = “car”;
mHomeTeam2 = “bufhome”;
mVisitorTeam2 = “arz”;
mHomeTeam3 = “carhome”;
mVisitorTeam3 = “buf”;

I would like to create classes for each of these then when they are rolled over be able to adjust the settings within each of these classes. So thats why I placed that in the loop. when each is rolled over, I would like to say change a set of values within the class for this clip along with having the ability to adjust others at the same time.

Example 1 team is playing the other team. If I click on the first team, I would like to deselect the second team. Should I not place the Object stuff in the loop and how do I update the constructor data?

gameClass = function(teamnum,sel,gamenum,visitorhome){
this.teamnum = 10;
this.sel = false;
this.gamenum = 1;
this.visitorhome = “visitorhome”;
}

gameClass.prototype = new MovieClip();

for (var i = 1; i<=gameCount; i++) {
Object.registerClass([“mHomeTeam”+i], gameClass);
[“homeTeam”+i].attachMovie([“mHomeTeam”+i],“homeTeam”+i,i-10);
[“homeTeam”+i].sel=false;
[“homeTeam”+i].gamenum=i;
[“homeTeam”+i].visitorhome=“home”;

Object.registerClass(this["mVisitorTeam"+i], gameClass);
this["visitorTeam"+i].attachMovie(this["mVisitorTeam"+i], this["visitorTeam"+i],i-270);
this["visitorTeam"+i].sel=false;
this["visitorTeam"+i].gamenum=i;
this["visitorTeam"+i].visitorhome="visitor";

}

The last post is a little difficult to understand. The flash movie files that I have are listed as variables and they seem to load just fine. Each of the movies should have its own class with variables (teamnum set to 10, sel set to false, gamenum set to 1, and visitorhome set to visitorhome)

gameClass = function(teamnum,sel,gamenum,visitorhome){
this.teamnum = 10;
this.sel = false;
this.gamenum = 1;
this.visitorhome = “visitorhome”;
}

The clips display ok and load up. I would like to as they are loading up to set these initial values to the i counter in my loop so I can then use these values in methods to adjust the look on the site.

When I run this, in debug mode it shows _level0.homeTeam1, _level0.homeTeam2 and so on with the correct variables associated to each. What I dont understand is in my class.protptype.On Rollover how do I access these variables and use them to run certain sections of other clips.

I attached the file so you can get an idea of really what I am attempting to do. Thanks again for your help…

Well, you didn’t attach anything… But once again, I think one of us didn’t understand how registerClass works. It is used to link a movie clip to a class. So that when you attach this clip, or drag and drop it from the library, it calls the constructor of the class and all. So if you have 1 movie clip in the library, you need to do that only once. I might be wrong.

What I dont understand is in my class.protptype.On Rollover how do I access these variables and use them to run certain sections of other clips.
I’m sorry I don’t understand the question. I’ll be waiting for the fla.

pom :slight_smile:

It will not let me attach the fla, is there a way that I can send it to you?

[email protected]

Did you receive the fla? I wasnt sure if it went out, my email at work has been screwy.

I got it, opened it, got a headache, closed it. I’ll try tomorrow :sleep:

haha, ok. I know its been giving me headaches for days now. Should be a simple thing to do, just not sure where i am going wrong with it.

thanks for your help.

OK, I’ve checked. But I don’t see the problem. I don’t have problems accessing the member data… Could you tell me exactly what’s wrong?

Thanks, I figured out what my problem was. I needed to create components that accepted the values when I attached the movie.

The triangle example from Macromedia was the key to getting it to work. Now im looking into implementing a drag and drop feature of the page. Looking for examples of this, they would also need to be components, I believe because each game would have its own ball that would be drag / dropped onto it and would need to know its component information (value, and other stuff).

Thanks for looking into this for me and im glad I was able to finally figure it out, it seems like an easy thing to do, I do it all the time in java.