Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 16th, 2004, 06:48 AM
sharen sharen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 16 sharen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old January 16th, 2004, 08:39 AM
Tann San Tann San is offline
Gotta get to the next screen..
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2003
Location: Legion of Dynamic Discord
Posts: 4,632 Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 7835 Folding Title: Novice Folder
Time spent in forums: 3 Weeks 14 h 52 m 21 sec
Reputation Power: 538
Facebook MySpace
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.
__________________
-Tann

-Vote for your favorite ActionScript editor here.

Reply With Quote
  #3  
Old January 16th, 2004, 08:51 AM
sharen sharen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 16 sharen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old January 16th, 2004, 09:50 AM
sharen sharen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 16 sharen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > use loaded movie as a button


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway