Ultrashock Forums > Flash > ActionScript
Buttons to switch between clips

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
Buttons to switch between clips
Old 2009-06-26

Hello,

I am new to this forum. Not an experienced Flash user. I need to include a swf file on my client's web page. The swf file includes 4 movie clips appearing one by one. Each clip links to their designated page. I want to have small buttons to let viewers to click and switch to the clip they want. When click, the still shot (may be the last frame) of the clip appears. Please refer to http://www.dell.com for an example. Can anyone advise step by step?

Thanks in advance!

kklui.
postbit arrow 3 comments | 108 views postbit arrow Reply: with Quote   
Registered User
kklui is offline
seperator
Posts: 3
2009-06-26
kklui lives in Canada
seperator

Ultrashock Member Comments:
jaseinatl jaseinatl is offline jaseinatl lives in United States 2009-06-27 #2 Old  
I can't help you with AS3, but in AS2, you could do it like this:

overview:

You are going to make a movieClip symbol that fades another movieClip in and out by adjusting the _alpha property of the embedded image.

Then, in another movieClip, you will make the buttons for each image you want to substitute for the fade effect.

When a button is clicked, the fading movieClip fades the image out and tells the parent object to load a new image. The parent object then loads the new image from the library and fades the image to 100 %.

the Actionscript you could use would be something like:

function buildImages() {
//create an array of images whose Linkage ID you setup in advance
this.imageList=new Array();
//each image should be named "image_n" where "n" is a number from 0 to the total number of images (5 in this example);
var imageCount:Number=5;
for (var i=0;i<imageCount;i++) {
this.imageList.push("image_"+i);
}
this.imageHolder=this.createEmptyMovieClip("imageHolder", this.getNextHighestDepth());
this.imageHolder.controller=this;
this.buildButtons();
}

function buildButtons() {
/*assume that you have a movieClip object with an embedded button and a text Field.
The text field's variable property is set to "label" and given the instance name "label_txt".
The button object is given an instance name of "btn";
*/
var imageCount:Number=this.imageList.length;
var buttonHolder:MovieClip=this.createEmptyMovieClip("buttonHolder", this.getNextHighestDepth());
for (var i=0;i<imageCount;i++) {
var label:String = i.toString();
var nm:String = "button_"+i;
var dp:Number=buttonHolder.getNextHighestDepth();
var ini:Object={label:label, id:i, controller:this};
var mc:MovieClip=buttonHolder.attachMovie("imageButton", nm, dp, ini);
mc.btn.onRelease=function () {
this._parent.controller.showImage(this._parent.id);
}
this.showImage(0);
}

public function showImage(id:Number) {
this.imageHolder.nextID=id;
this.imageHolder.onEnterFrame=function () {
this.image_mc._alpha--;
if (this.image_mc._alpha<=0) {
this.image_mc._alpha=0;
delete this.onEnterFrame;
this.controller.loadImage(this.nextID);
}
}
public function loadImage(id:Number) {
var lnk:String = this.imageList[id];
var mc:MovieClip=this.imageHolder.image_mc;
removeMovieClip(mc);
var mc:MovieClip=this.imageHolder.attachMovie(lnk, "image_mc", 100, {_alpha:0});
this.imageHolder.onEnterFrame=function () {
this.image_mc._alpha++;
if (this.image_mc._alpha>=100) {
this.image_mc._alpha=100;
delete this.onEnterFrame;
}
}
}

This is kinda rough code and I should spend some time to explain it better, but I have to run. Hopefully this will get you started and I can answer any questions you have. If you are more of a beginner at Flash than this, let me know and I will try to put a file together for you.

Hope this gets ya started,

Jase
Reply With Quote  
kklui kklui is offline kklui lives in Canada 2009-06-27 #3 Old  
Thanks Jase! I will try to explore base on your reply. If you could prepare a FLA file for reference, that would be great to me.
Reply With Quote  
kklui kklui is offline kklui lives in Canada 2009-06-27 #4 Old  
Hi Jase,

I still cannot figure out how to do that. I'm just a beginner. Could you please explain a little bit more in detail like which layer I should put what... etc. Appreciate your great help!

kklui.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: