To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-21-2004, 05:57 PM   #1
Mctittles
Senior Member
 
Join Date: Jan 2003
Location: Nebraska
Posts: 440
For Loop and Array onPress Assignments

I have a script like this to assign a number of buttons to change a variable on rollover:
code:

for (logoCount=1; logoCount<=6; logoCount++) {

temp = eval("logo"+logoCount);
temp.onRollOver = function() {
scaleFactor[logoCount] = true;
};
temp.onRollOut = function() {
scaleFactor[logoCount] = false;
};

}



The problem I have is the scaleFactor array gets assigned to the variable named logoCount when you rollOver any of the move clips. So rolling over logo1 makes scaleFactor[logoCount]=true, but logoCount is irrelavant after this loop is done. I want it so when you rollOver logo1 then scaleFactor[1]=true and rolling over logo2 then scaleFactor[2]=true and so on. Anyone know a looping way to do this?
__________________
thecardchest - My full flash site.
Mctittles is offline   Reply With Quote
Old 10-21-2004, 06:11 PM   #2
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
To answer your immediate question, you can create your own properties on buttons. I create a property called idx and use it to store the logoCount number.

Then, within the event handler, you can use this.property to refer to the thing you stored.

code:

for (logoCount=1; logoCount<=6; logoCount++)
{
temp = eval("logo"+logoCount);
temp.idx = logoCount; // store it here...
temp.onRollOver = function()
{
scaleFactor[this.idx] = true;
};
temp.onRollOut = function() {
scaleFactor[this.idx] = false;
};
}



If it were me, I probably wouldn't store scaleFactor in a separate array, but would also assign scaleafactor to each individual button, just I'm doing with idx. I like to keep stuff associated with buttons or movieclips in the buttons or movieclips.

code:

for (logoCount=1; logoCount<=6; logoCount++)
{
temp = eval("logo"+logoCount);

temp.onRollOver = function()
{
this.isScaling = true;
};
temp.onRollOut = function() {
this.isScaling = false;
};
}

__________________

Last edited by jbum; 10-21-2004 at 06:13 PM.
jbum is offline   Reply With Quote
Old 10-21-2004, 06:19 PM   #3
Mctittles
Senior Member
 
Join Date: Jan 2003
Location: Nebraska
Posts: 440
Oh yea duh, just a variable within the movie clip for each button. Thanks for the help man. I am actually just the opposite of you when it comes to buttons it seems. I like to keep all the events for buttons (and all code actually) in a seperate or root actionscript file so when changes need to be made to a bunch of things, I don't have to movie explore all over to find them.
__________________
thecardchest - My full flash site.
Mctittles is offline   Reply With Quote
Old 10-21-2004, 06:21 PM   #4
Mctittles
Senior Member
 
Join Date: Jan 2003
Location: Nebraska
Posts: 440
Or wait, I think I misread what you said wrong. By storing them in the buttons or clips, you meant in relative with your code, not actually in the actionscript for the thing?
__________________
thecardchest - My full flash site.
Mctittles is offline   Reply With Quote
Old 10-21-2004, 06:30 PM   #5
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
Yes, that's right.

I agree with you that it's best to keep all the actionscript in a single frame script so you don't go crazy having to find it.

I just like to keep the variables associated with objects attached to those objects, rather than in separate data structures. It's an OOP thing...
__________________
jbum is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

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

Forum Jump


All times are GMT -4. The time now is 11:23 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.