LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
  #1  
Old 05-05-2008, 05:34 PM
jaegow's Avatar
jaegow jaegow is offline
Registered User
 
Join Date: Aug 2007
Posts: 32
Rep Power: 0
jaegow is on a distinguished road
Consolidation of ActionScript [F8]&[F9]

have been running into the same problem multiple times and I know there is an easier way to do this.. any ideas out there?

here would be an example of some code:

PHP Code:

btn1.onPress = function(){
    do 
the same thing;
    }
btn2.onPress = function(){
    do 
the same thing;
    }
btn3.onPress = function(){
    do 
the same thing;
    }
btn4.onPress = function(){
    do 
the same thing;
    } 
  #2  
Old 05-05-2008, 05:47 PM
[PAUL FERRIE]'s Avatar
[PAUL FERRIE] [PAUL FERRIE] is offline
Glasgow Flash Developer
 
Join Date: Feb 2005
Location: United Kingdom
Posts: 7,756
Rep Power: 16
[PAUL FERRIE] is on a distinguished road
Code:
btn1.onPress = function(){
    doStuff(_name)
    }
btn2.onPress = function(){
    doStuff(_name)
    }
btn3.onPress = function(){
    doStuff(_name)
    }
btn4.onPress = function(){
    doStuff(_name)
    }  
function doStuff(butName){
//Take the first 3 characters away from the name and leave the number. 
var id = butName.slice(3)
//Do stuff  to/with the number here
}
Is that what your talking about?
__________________
.:To me AS is like LEGO, Only for the big Kids :.
- Site - Blog - Glasgow Flasher - Activeden

- bringmadeleinehome.com
  #3  
Old 05-05-2008, 06:22 PM
jaegow's Avatar
jaegow jaegow is offline
Registered User
 
Join Date: Aug 2007
Posts: 32
Rep Power: 0
jaegow is on a distinguished road
I was thinking of maybe a loop...
and I know this won't work...

PHP Code:

for (i=0i<5i++) {
var 
mc MovieClip "btn"+i;
mc.onPress.function=(){
do 
the same thing;
}

Or maybe an array...
also, keep in mind that I know this doesn't work

PHP Code:

var mc:Array = ["btn1","btn2","btn3","btn4"];
mc.onPress.function=(){
do 
the same thing;

  #4  
Old 05-05-2008, 06:26 PM
[PAUL FERRIE]'s Avatar
[PAUL FERRIE] [PAUL FERRIE] is offline
Glasgow Flash Developer
 
Join Date: Feb 2005
Location: United Kingdom
Posts: 7,756
Rep Power: 16
[PAUL FERRIE] is on a distinguished road
Why wont this work?
Actionscript:
for (i=0; i<5; i++) {
var mc : MovieClip = "btn"+i;
mc.onPress.function=(){
doStuff(_name)
}
} 
function doStuff(butName){
//Take the first 3 characters away from the name and leave the number. 
var id = butName.slice(3)
//Do stuff  to/with the number here
}
I have seen scottae suggest his method a few times.
__________________
.:To me AS is like LEGO, Only for the big Kids :.
- Site - Blog - Glasgow Flasher - Activeden

- bringmadeleinehome.com
  #5  
Old 05-05-2008, 06:39 PM
jaegow's Avatar
jaegow jaegow is offline
Registered User
 
Join Date: Aug 2007
Posts: 32
Rep Power: 0
jaegow is on a distinguished road
I don't know too much about the slice stuff that you have here but if the...
PHP Code:

var mc:MovieClip "btn"+1
...would be recognized, the slice wouldn't be needed; it would run just fine without it(for what I am trying to do).
  #6  
Old 05-05-2008, 06:40 PM
jaegow's Avatar
jaegow jaegow is offline
Registered User
 
Join Date: Aug 2007
Posts: 32
Rep Power: 0
jaegow is on a distinguished road
sorry....

meant to have...

PHP Code:

var mc:MovieClip "btn"+i;

not

var mc:MovieClip "btn"+
;
 


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

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash ActionScript 2.0 Learning Guide chetan1 Flash 8 0 05-12-2008 06:14 AM
ACtionscript 2.0 vs. 1.0 Issue funk45 Actionscript 2.0 Components 1 11-07-2005 05:58 AM
When I "convert to symbol" my Actionscript gets buried! sunstorm Flash 5 and below 2 12-04-2004 11:05 PM
Can ActionScript check windows registry / txt. file? janice_2k Flash MX ActionScript 0 06-04-2004 10:27 AM
JOB OPENING: Flash ActionScript Programmer barn Work/Job Opportunities 0 09-10-2001 11:41 PM




All times are GMT. The time now is 08:21 PM.