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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnPress Event of movieclip

Status
Not open for further replies.

emblewembl

Programmer
Joined
May 16, 2002
Messages
171
Location
GB
I've got a flash movie with some dynamically loaded movieclips which hold a thumbnail of an image. All images from a specified folder are loaded. When each thumbnail is clicked on I want the main large image to change and show the thumbnail in full size. I've tried to add an onPress event to each movieclip but they all end up linking to the last thumbnail loaded - i'm very new to actionscript (I normally develop in C#) so be gentle with me! Any help greatly appreciated :) Here's the full code:

Code:
var x = new XML();

var path = "\\images\\";

//thumbs
var xPos = 466;
var yPos = 103;
var tWidth = 44;
var tHeight = 44;
var tSpace = 5;
var numPhotos = 0;

//main
var xMain = 96;
var yMain = 20;
var mWidth = 268;
var mHeight = 400;

x.ignoreWhite = true;
x.onLoad = function(success) {
	if (success) {
		x=0;

		//main
		var mcMain = _root.createEmptyMovieClip( 'main'+i, i+10 );
		mcMain._x = i*110;

		var imgMain = mcMain.createEmptyMovieClip( 'mImg', 1 );
		imgMain._visible = false;
		imgMain.loadMovie(path + this.childNodes[0].childNodes[0]);
		mcMain.onEnterFrame = function(){
			var t = imgMain.getBytesTotal();
			var l = imgMain.getBytesLoaded();
			if( l == t && t >100 ){
				this.onEnterFrame = null;
				
				this._width = mWidth;
				this._height = mHeight;
				this._x = xMain;
				this._y = yMain;
				imgMain._visible = true;
				
			}
		}

		//thumbs
		for( i in this.childNodes ){
			var mc = _root.createEmptyMovieClip( 'pic'+i, i+10 );
			mc._x = i*110;
			var img = mc.createEmptyMovieClip( 'img', 1 );
			img._visible = false;
			var imgPath = path + this.childNodes[i].childNodes[0];
			trace("Path 1: " + imgPath);
					
			img.loadMovie(imgPath);
			
			mc.onEnterFrame = function(){
				var t = img.getBytesTotal();
				var l = img.getBytesLoaded();
				if( l == t && t >100 ){
					this.onEnterFrame = null;
					this._width = tWidth;
					this._height = tHeight;
					this._x = xPos;
					this._y = yPos;
					this.onPress = function(){
						imgMain.loadMovie(imgPath);
						trace("Path 2: " + imgPath);
					}
					
					xPos = xPos + tWidth + tSpace;
					numPhotos = numPhotos + 1;
					
					if (numPhotos > 3)
					{
						//build next row of thumbnails
						xPos = 466;
						yPos = yPos + tHeight + tSpace;
						numPhotos = 0;
					}
					
					img._visible = true;
					outlinePortrait._visible = false;
				}
			}
		}
	} else {
		trace( 'failed to load xml' );
	}
}
x.load('images.xml');

i love chocolate
 
At first glance at your code:

[tt]var mcMain = _root.createEmptyMovieClip('main'+i, i+10);[/tt]

Where is this "i" coming from, since this line is not inside the loop?

(Don't eat too much chocolate or your nose start bleeding)

Kenneth Kawamoto
 
Good point! I got this code from a tutorial so i've probably missed something - however my main image and thumbnails load fine, ii just need to know hot to get the onclick event of the thumbnail working so that when each thumbnail is clicked the main image shows the big version of that particular thumbnail. Any ideas?

i love chocolate
 
[tt]this.onPress = function(){
imgMain.loadMovie(imgPath);
trace("Path 2: " + imgPath);
}[/tt]

Here you're telling your thumbnails to load "imgPath" to "imgMain" on mouse press. But "imgPath" is the path to your thumbnail by the looks of it.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top