Jump to content
Search Community

newbie:How to tween the function not the mc

sms776677 test
Moderator Tag

Recommended Posts

I am trying to add a tween (this is the first time I've done this) that triggers once a new thumb is clicked or the next or prev buttons are pushed that will slide the current image off to the right simultaneously fading it out, revealing the called image. The code as is is tweening the called image in while the current disappears. Please any suggestions to point me in the right direction would be awesome. :)

 

import gs.*;
import gs.easing.*; 
OverwriteManager.init(OverwriteManager.ALL); 

var pic_alpha = 3;
var scroll_speed = 7;
var thum_roll_alpha = 60;
var space_thumb = 1;
var mc_path = this;
var xmlFile = "Portraits.xml";
var xml:XML = new XML ();
xml.ignoreWhite = true;
xml.load (xmlFile);

xml.onLoad = function () {
var nodes = this.firstChild.childNodes;
	numItems = nodes.length;
	image = [];
	thumbnails = [];
for (var i = 0; i < numItems; i++) {
	var attr = nodes[i].attributes;
	image[i] = attr.image;
	thumbnails[i] = attr.thumb;
	thumb_init(i);
}
firstImage();
};
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
	prevImage();
} else if (Key.getCode() == Key.RIGHT) {
	nextImage();
}
};
Key.addListener(listen);
nb_pic = 0;

function pic_number() {
current_pos = nb_pic+1;
pos_txt.text = current_pos+" / "+numItems;
}
next_BTN.onRelease = function(){ 
if (nb_pic<(numItems-1)) {
	nb_pic++;
	if (loaded == filesize) {
		picture._alpha = 100;
		picture.loadMovie(image[nb_pic], 1);
		TweenLite.from(picture, 1.6, { _x:"730", _y:"0", ease:Expo.easeInOut, onComplete:clear(), onCompleteParams:[]});
		pic_number();
	}
}
}
prev_BTN.onRelease = function(){ 
if (nb_pic>0) {
	nb_pic--;
	picture._alpha = 0;
	picture.loadMovie(image[nb_pic], 1);
	TweenLite.from(picture, 1.6, { _x:"730", _y:"0", ease:Expo.easeInOut, onComplete:clear(), onCompleteParams:[]});
	pic_number();
}
}
this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
	preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
	preloader._visible = false;
	if (picture._alpha<100) {
		picture._alpha += pic_alpha;
	}
}
};
this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
	preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
	preloader._visible = false;
	if (picture._alpha<100) {
		picture._alpha += pic_alpha;
	}
}
};
function nextImage() {
if (nb_pic<(numItems-1)) {
	nb_pic++;
	if (loaded == filesize) {
		picture._alpha = 0;
		picture.loadMovie(image[nb_pic], 1);
		pic_number();
	}
}
}
function prevImage() {
if (nb_pic>0) {
	nb_pic--;
	picture._alpha = 0;
	picture.loadMovie(image[nb_pic], 1);
	desc_txt.text = description[nb_pic];
	pic_number();
}
}
function firstImage() {
if (loaded == filesize) {
	picture._alpha = 0;
	picture.loadMovie(image[0], 1);
	desc_txt.text = description[0];
	pic_number();
}
}
function clear() {
if (loaded == filesize) {
	picture._alpha = 0;
	picture._x = 0;
	picture._y = 0;
	picture.loadMovie(image[0], 1);
	desc_txt.text = description[0];
	pic_number();
}
}
function thumbScroll() {

this.createEmptyMovieClip("scroller", 1000);
scroller.onEnterFrame = function() {
	if ((mc_path._ymouse>=thumbnail_mc._y) && (mc_path._ymouse<=thumbnail_mc._y+thumbnail_mc._height)) {
		if ((mc_path._xmouse>=(hit_right._x-40)) && (thumbnail_mc.hitTest(hit_right))) {
			thumbnail_mc._x -= scroll_speed;
		} else if ((mc_path._xmouse<=(hit_left._x+40)) && (thumbnail_mc.hitTest(hit_left))) {
			thumbnail_mc._x += scroll_speed;
		}
	} else {
		delete scroller.onEnterFrame;
	}
};
}
function thumb_init(k) {
thumbnail_mc.createEmptyMovieClip("t"+k, thumbnail_mc.getNextHighestDepth());
tlistener = new Object();
tlistener.onLoadInit = function(target_mc) {
	target_mc._x = (target_mc._width+space_thumb)*k;
	target_mc.pictureValue = k;
	target_mc.onRelease = function() {
		 nb_pic = this.pictureValue-1;
		//////////------------------------------------->
		//trying tweens out ...
		TweenLite.from(picture, 1.6, { _x:"730", _y:"0", ease:Expo.easeInOut, onComplete:clear(), onCompleteParams:[]});
		nextImage();
	};

		//------------------------------------------------>
	target_mc.onRollOver = function() {
		this._alpha = thum_roll_alpha;
		thumbScroll();
	};
	target_mc.onRollOut = function() {
		this._alpha = 100;
	};
};
picture_mc = new MovieClipLoader();
picture_mc.addListener(tlistener);
picture_mc.loadClip(thumbnails[k], "thumbnail_mc.t"+k);

}

Link to comment
Share on other sites

If you want to set up a sequence, just use the "delay" special property or look into using the brand new TimelineLite or TimelineMax classes in v11 (http://blog.greensock.com/v11beta/).

 

Also, I noticed that you're putting "()" after your onComplete functions which will force them to get called immediately.

 

BAD: onComplete:myFunction()

GOOD: onComplete:myFunction

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...