Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using instance name of any button 1

Status
Not open for further replies.

dingleberry

Programmer
Dec 13, 2002
143
US
Hi,

I've got a movie that loads images stored on the server in a seperate directory. I do this because preloading all of the images (some 500) would take an awful amount of time. I'm trying to optimize the process so instead of doing

on (release) {
pic = "image2.jpg";
loadMovie("images/"+pic, "_root.blankmovie");
}

for one button and

on (release) {
pic = "image3.jpg";
loadMovie("images/"+pic, "_root.blankmovie");
}

for another and so on and so on like 500 times, I'd like to make a global statement on main movie like

_global.pic = Button._name

and then for entire movie do something like

on {???everybutton???}(release) {
loadMovie("images/"+pic, "_root.blankmovie");
}


but I really have no idea how to tell the movie that the button I'm referring to is the one I just clicked. Any ideas? I'm open to a complete change of thinking here too. I'm kinda new to flash and may be in over my head. If you know of a better way to do this, let me know or if you just know the correct syntax of what I'm trying to do, I'd love some pointers.

tia,
dan
 
this might help.....might cause more problems

assuming all buttons are on main timeline and that they are just used for loading images

then main timeline

Button.prototype.onRelease = function(){
clicked = String(this).substring(9);
loadMovie("images/" + clicked + ".jpg",_root.blankmovie)
}

thing is you now have to give all 500 buttons instance names that are the same as the pic names

ie button 1 would have name image1 and so on

shorter code but still a pain.

stick a trace(clicked) in there first couple of times in case you have to change the number in the substring

_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
Hey Bill,

assuming all buttons are on main timeline and that they are just used for loading images

Therein lies the problem. Some of my buttons are called from movies that are embedded as symbols in my main movie. Will that prevent your solution from working?

Dan
 
thats the problem. the idea behind the code is just to strip off the path and leave the instance name.

so on main timeline path returned by a button click would be _level0.button1 and all the code was doing reducing that to button1

if the paths are all different then this method wont work

_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
correction it can be made to work if all the button instance names / image names are the same length

Button.prototype.onRelease = function(){
clicked = String(this)
y = clicked.substring(clicked.length-6,clicked.length)
loadMovie("images/" + y + ".jpg",_root.blankmovie)
}

this works if all names are 6 chars no matter the path

_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
You're kidding. So If an instance name of a button is ima001 and the next is like ima002 and so on ... ima500 than it will work?
dan
 
yes
try it and see

_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
Bill, I'm very sorry it has taken me this long to get back to you and let you know that you are my new hero. Yup, it used to be Tom Hanks, and now it's you. Seriously, you are a miracle worker to have figured that out. Thanks!

dan
 
Okay, how about one more for the road...

That variable you are defining as y. Can I assign that to a button action anywhere in the movie. What I'm trying to do is do a

on (release) {
getURL ("javascript:NewWindow=window.open(' NewWindow.focus();void(0);");
}

Its tough to see up there but if you read the link I'm trying to reference in the javascript popup window you'll see the y in there. For some reason, that y is not defined to the entire movie so when I click on a button and use the y as a variable, flash tells me it is undefined. Any ideas on how to make it globally accessable throughout the movie?

Thanks Bill,
Dan
 
Forget it Bill,

I figured it out thanks to a post you submitted earlier this week to kdelacruz. Damn you're good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top