|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
use loaded movie as a button
Hi,
I'm trying to load images dynamically on a Flash page and I want these images to work as buttons. Any ideas? Here's what I got so far: I have a frame with 4 movie clips on it which are just white squares. Under the properties for each movie clip, I have changed the type to "button" and given the instance names "pic0", "pic1", "pic2" and "pic3" respectively. In the actionscript page for this frame, I have the following code: brand_array = Array("company1", "company2", "company3", "company4"); for (i=0; i<brand_array.length; i++) { img = "images/" + brand_array[i] + "_logo.jpg"; loadMovie(img, "pic"+i); } So far all is peachy. The 4 company logos I need appear where the empty squares were placed. But how do I make these images buttons? I've tried two things: 1. Writing a function for each movie clip. Heres one example: In the actionscript page for this frame, I have the following code: pic0.onPress = function() { trace("gets here"); ... do more stuff ... } This doesn't work. I want to avoid this way anyway because I'd rather have dynamically created functions which brings me to #2. 2. Try to dynamically create a function. So the IF statement above changes to: for (i=0; i<brand_array.length; i++) { img = "images/" + brand_array[i] + "_logo.jpg"; loadMovie(img, "pic"+i); eval("pic" + i + ".onPress = function() {trace("hello"); .. and then calls another function ... }"); } But this doesn't work either. Any help would be greaty appreciated! Sharen. |
|
#2
|
|||
|
|||
|
Hi, the first part of your question may be not working because the clips you are loading into are buttons. Try making them movie clips to start with. That should allow your pic0.onPress() function to work.
The second part of your question could be achieved with function prototyping...well really once you got it working anyway you could switch to prototyping...anyways to get it to work as is, change your eval line to: Code:
eval("pic" + i).onPress = function()
{
trace("hello");
.. and then calls another function ...
};
think that will do it for now. |
|
#3
|
|||
|
|||
|
Hi Tann,
Thanks for the speedy reply! I still seem to be having problems though. I changed the clips back to movie clips and the IF statement is now as follows: for (i=0; i<brand_array.length; i++) { img = "images/" + brand_array[i] + "_logo.jpg"; loadMovie(img, "pic"+i); eval("pic" + i).onPress = function() { trace("brand changed to " + brand_array[i]); ... call to other function ... }; } The images are loading ok. But there still isn't any button action happening. The cursor doesn't change into a hand when over the images and nothing happens when I click on them. I tried changing the blank clips back to buttons but that doesn't seem to do anything either. Any other suggestions?? Cheers, Sharen. |
|
#4
|
|||
|
|||
|
Ok Tann + everyone... I got it working.
I've kept the images loading in movie clips called pic0, pic1, etc. And now I've added transparent rectangles over top of them called log0, log1, etc. and the code is now: for (i=0; i<brand_array.length; i++) { img = "images/" + brand_array[i] + "_logo.jpg"; loadMovie(img, "pic"+i); eval("log" + i).onPress = function() { str = this._name; num = str.slice(3); // to get the current i _global.brand = brand_array[num]; ... la la la... } Thanks for your help though. |
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > use loaded movie as a button |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|