A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [RESOLVED] Making The Movieclip loop

Hybrid View

  1. #1
    :
    Join Date
    Dec 2002
    Posts
    3,518
    button code added to code from first post...
    Code:
    stop();
    
    var picSpace = 10;
    var minDist = 8;
    var picArray = new Array();
    var picTotal = 0;
    var holder = this.createEmptyMovieClip("holder", 0);
    holder._y = 250;
    var btnsX = 0;
    var btnsY = 0;
    
    function addButton(num) {
    	// movie clip in library with export linage of "btnMC", has dynamic text field instance 'tag'
    	var btn = attachMovie("btnMC", num, this.getNextHighestDepth(), {_x:btnsX, _y:btnsY});
    	btn.tag.text = num+1;
    	btnsX += btn._width+2;
    	btn.onPress = doBtnPress;
    }
    function doBtnPress() {
    	var valX = (0-picArray[Number(this._name)][1].x1);
    	var dist = valX-holder._x;
    	dist = Math.abs(dist);
    	var d = (dist>60) ? (dist>180) ? 20 : 40 : 80;
    	var tc = 0;
    	var begX = holder._x;
    	var endX = valX-holder._x
    	holder.onEnterFrame = function() {
    		var t = ++tc;
    		this._x = endX*((t=t/d---1)*t*t+1)+begX;
    		if (tc == d) {
    			delete this.onEnterFrame;
    		}
    	};
    }
    function doLoadInit(mc) {
    	var xOffset = 0;
    	for (i=0; i<picTotal; i++) {
    		holder[i]._x = xOffset;
    		picArray[i][1] = {x1:holder[i]._x, x2:holder[i]._x+holder[i]._width};
    		xOffset += holder[i]._width+picSpace;
    	}
    	mc.onPress = doPress;
    }
    
    function loadXML(loaded) {
    	if (loaded) {
    		var xmlNode = this.firstChild;
    		picTotal = xmlNode.childNodes.length;
    		trace(picTotal);
    		for (i=0; i<picTotal; i++) {
    			var picInfo = [xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue];
    			var p = holder.createEmptyMovieClip(i, i);
    			my_mcl.loadClip(picInfo[0],p);
    			picArray.push(picInfo);
    			addButton(i);
    		}
    	} else {
    		content = "file not loaded!";
    	}
    	delete xmlNode;
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("dragthrow.xml");
    var my_mcl = new MovieClipLoader();
    var myListener = new Object();
    myListener.onLoadInit = doLoadInit;
    my_mcl.addListener(myListener);
    //
    function doPress() {
    	var idex = Number(this._name);
    	var anchorX = holder._xmouse;
    	var pressX = _root._xmouse;
    	holder.onEnterFrame = function() {
    		this._x = _root._xmouse-anchorX;
    	};
    	holder.onMouseUp = function() {
    		var dist = _root._xmouse-pressX;
    		var dir = (dist>0) ? 0 : 1;
    		dist = Math.abs(dist);
    		if (dist>minDist) {
    			var endX = ((dir == 0) ? Stage.width-picArray[idex][1].x2 : 0-picArray[idex][1].x1)-this._x;
    			if (dir == 0 && endX<0 && idex>0) {
    				endX = (Stage.width-picArray[idex-1][1].x2)-this._x;
    			}
    			if (dir == 1 && endX>0 && idex<picTotal-1) {
    				endX = (0-picArray[idex+1][1].x1)-this._x; 
    			}
    			var begX = this._x;
    			var d = (dist>60) ? (dist>180) ? 20 : 40 : 80;
    			var tc = 0;
    			this.onEnterFrame = function() {
    				var t = ++tc;
    				this._x = endX*((t=t/d---1)*t*t+1)+begX;
    				if (tc == d) {
    					delete this.onEnterFrame;
    				}
    			};
    		} else {
    			trace("selected: "+idex);
    			delete this.onEnterFrame;
    		}
    		delete this.onMouseUp;
    	};
    }

  2. #2
    Junior Member
    Join Date
    May 2010
    Posts
    16
    thank you for the code its working great can u explain me how the thing is working and if i want to add fade in and fade out effect to the images..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center