how to stream video for flash with as2 and netstream

Post Reply
darknkreepy3#
Site Admin
Posts: 254
Joined: Tue Oct 27, 2009 9:33 pm

how to stream video for flash with as2 and netstream

Post by darknkreepy3# »

here's a simple example in as2 that allows you to stream all the way up to 1920x1080 and 15mbps in flash as2.
yes, old and crusty actionscript 2 and a normal non handheld device, called a computer.

remember the higher the resolution and larger the stream, the stronger the GPU you will need. CPU computation of a stream is not the way to go. ever. unless it is 1999.

Below this I will list the actionscript libraries to finish this example
[ease5.as][easeFormulas.as][createMovieClip2.as]

the folder structure is simple, remember to have the .AS files in your root, and your site in it's folder, as this player is one deep

[htdocs]*.AS[yoursite][mach]test_video.swf(test.video.fla)

test_video.fla

Code: Select all

#include "../../createMovieClip2.as"
#include "../../ease5.as"
#include "../../easeFormulas.as"
System.security.allowDomain("*"); 
/*
Flash Media Player v4.0 by Kristoffe Brodeur. ©2009 All Rights Reserved.
07-22-2009 added a seek sensitive time bar and a volume control drag button
*/
//-----
function stop_timeBar()
	{
	bar_time1.bar_currTime._width=0;
	T1.mach_timeBar.inst.onEnterFrame=function()
		{
		//
		}
	}
//----------
function init_timeBar()
	{
	T1.barLimit=bar_time1.bar_colorTime._width;
	T1.mach_timeBar=new createEM(T1.root,1000,0,0);
	T1.mach_timeBar.inst.onEnterFrame=function()
		{
		currTime=parseFloat(T1.ns.time);
		totalA=parseFloat(T1.ns.mData["duration"]);
		currProg=currTime/totalA;
		progPixels=T1.barLimit*currProg;
		bar_time1.bar_colorTime._width=progPixels;
		//
		init_timeOutput(currTime);
		//
		if(bt_seek1.searching==false)
			{
			bt_seek1._x=bar_time1._x+(bar_time1._width*currProg);
			}
		}
	}
//----------
function replayOn()
	{
	bt_replay._visible=true;
	T1.a_replayOn=new ease(bt_replay,"_alpha","linear",-1,true,0,100,10);
	T1.a_replayOn.easeAction=function()
		{
		}
	}
//----------
function replayOff()
	{
	T1.a_replayOff=new ease(bt_replay,"_alpha","linear",-1,true,100,-100,10);
	T1.a_replayOff.easeAction=function()
		{
		bt_replay._visible=false;
		}
	}
//----------
function init_timeOutput(sentTime)
	{
	tMin=Math.floor(sentTime/60);
	tSec=Math.floor(sentTime-(tMin*60));//because 1-29 extras frames in a second can lead to 22.5 seconds etc. 22 is roudned down
	//
	if(tMin<10)
		{
		tTime="0";
		}
	tTime+=tMin+":";
	//
	if(tSec<10)
		{
		tTime+="0";
		}
	tTime+=tSec;
	mc_timeOutput1.tF_A.text=tTime;
	}
//----------
function init_player(sentPar,sentAddy,sentVid,sentTitle)
	{
	trace(sentPar+newline+sentAddy+newline+sentVid+newline+sentTitle);
	replayOff();
	T1.rootPar=sentPar;
	//
	if(T1.ns)
		{
		closeVideo();
		}
	T1.addy=sentAddy;
	T1.vid=sentVid;
	T1.nc=new NetConnection();
	T1.nc.connect(null);
	T1.ns=new NetStream(T1.nc);
	ns.setBufferTime(16);
	//-----
	T1.ns.onMetaData = function(infoObject:Object)
		{
	    this.mData=new Array();
		//
		for(var propName:String in infoObject)
			{
        	this.mData[propName]=infoObject[propName];
			trace(propName + " = " + infoObject[propName]);
			}
		tDur=parseFloat(this.mData["duration"]);
		init_timeOutput(tDur);
		}
	T1.ns.onStatus = function(info)
		{ 
		//
		if(info.code=="NetStream.Play.Stop")
			{
			my_video.clear(); 
			stop_infoBar();
			//replayOn();
			nextVideo();
			}
		}
	videoPlayer.attachVideo(T1.ns);
	mach_vol.createEmptyMovieClip("mc_vol",0);
	mach_vol.mc_vol.attachAudio(T1.ns);
	mach_vol.snd=new Sound(mach_vol.mc_vol);	
	//
	v_play.onRelease=function()
		{
		playVideo();
		}
	//
	v_pause.onRelease=function()
		{
		pauseVideo();
		}
	playVideo();
	}
//----------
function pauseVideo()
	{
	T1.ns.pause();	
	}
//----------
function playVideo()
	{
	init_timeBar();
	T1.ns.play(T1.addy+T1.vid);
	}
//----------
function nextVideo()
	{
	//single play function for myspace only
	//replayOn();
	//tF_debug.text="[nextVideo()]"+T1.rootPar.vidDone;
	trace("VIDEO DONE INSIDE OF THE SWF PLAYER!");
	T1.root.par.vidDone();
	}
//----------
function vidDone()
	{
	trace("solotest worked, this video is done. this function should reside in the calling swf parent");
	}
//-----
function setVol()
	{
	tDist=mach_vol.volLimit1._width;
	currPos=mach_vol.bt_volSlider._x-mach_vol.volLimit1._x;
	prop=Math.floor((currPos/tDist)*100);
	mach_vol.snd.setVolume(prop);
	}
//-----
function init_GUI()
	{
	bt_seek1.searching=false;
	bt_seek1._y=bar_time1._y+bar_time1._height/2;//center to the red bar
	mc_backArt1._visible=false;
	bt_replay.tF_A.text="PLAY";
	//tF_debug._visible=false;
	bar_time1.onRelease=function()
		{
		distX=this._width;
		currPos=this._xmouse;
		prop=(currPos/distX);
		//trace("_xmouse:"+this._xmouse);
		//trace("_width:"+distX);
		//trace("prop%:"+prop);
		totalSecs=parseFloat(T1.ns.mData["duration"]);
		seekSecPos=totalSecs*prop;
		T1.ns.seek(seekSecPos);
		}
	//bt_replay._visible=false;
	//define vol drag limits
	mach_vol.bt_volSlider.onPress=function()
		{
		tY=this._y;
		startDrag(this,true,0,tY,mach_vol.volLimit1._width,tY);
		//setInterval(function to call,milliseconds x/1000)
		this.updateVol=setInterval(setVol,100);
		}
	mach_vol.bt_volSlider.onRelease=function()
		{
		clearInterval(this.updateVol);
		stopDrag();
		}	
	T1.volStart=75;
	tDist=mach_vol.volLimit1._width;
	currPos=(tDist/100)*T1.volStart;
	mach_vol.bt_volSlider._x=currPos;
	}
//-----
var T1=new Object();
T1.root=this;
init_GUI();
/*
addy,vid,vidTitle
*/
//
if(T1.root.addy==undefined)
	{T1.addy="../videos/";}
else
	{T1.addy=T1.root.addy;}

if(T1.root.vid==undefined)
	{T1.vid="Orpheum-me4.f4v";}
else
	{T1.vid=T1.root.vid;}

if(T1.root.vidTitle==undefined)
	{T1.vidTitle="Orpheum cbr test";}
else
	{T1.vidTitle=T1.root.vidTitle;}
//tF_debug.text=T1.addy+T1.vid;	
tF_debug.text=T1.vidTitle;
init_player(T1.root,T1.addy,T1.vid,T1.vidTitle);
ease5.as

Code: Select all

/*
ease5.as ©2009 by Kristoffe Brodeur. All Rights Reserved.
requires easeFormulas.as to function.
#include "./easeFormulas.as" in your code where ./ is the relative path to the file ../ ../../ etc
03-24-2009	complete redo of track system holding ease tracks
03-31-2009	fixed delete bug before easeAction call
04-01-2009	fixed onEnterframe=function(){}; bug where after all tracks were cut off nothing would work
			when later called because onEnterFrame wasn't undefined and was simply f(){};
04-07-2009  added # for a number to use with *.useNum(sNum) and prototype *.go() for ready and waiting eases triggered by *.go();
08-11-2009 fixed the possible contflict with 'tgt' as a variable in this function(class) by using '__tgt' and maybe 'tgt' externally
*/
function easeVal(eType,eCF,eTD,eTF,eX1)
	{
	eVal=0;
	//
	switch(eType)
		{
		case ("linear"):
			eVal=easeLinear(eCF,eTD,eTF);
			break;
		case ("inBack"):
			eVal=easeInBack(eCF,eTD,eTF,eX1);//overshoot is 4th variable
			break;
		case ("outBack"):
			eVal=easeOutBack(eCF,eTD,eTF,eX1);//overshoot is 4th variable
			break;
		case ("inQuad"):
			eVal=easeInQuad();
			break;
		case ("outQuad"):
			eVal=easeOutQuad();
			break;
		case ("inoutQuad"):
			eVal=easeInOutQuad();
			break;
		case ("inElastic"):
			eVal=easeInElastic();
			break;
		case ("outElastic"):
			eVal=easeOutElastic();
			break;
		case ("inBounce"):
			eVal=easeInBounce(eCF,eTD,eTF);
			break;
		case ("outBounce"):
			eVal=easeOutBounce(eCF,eTD,eTF);
			break;
		}
	//
	return eVal;	
	}
//-----
ease.prototype.go=function()
	{
	//trace("GO!"+this._track);
	this.mc_tracks.easeArr[this._track]._go=true;
	}
//-----
function ease(sMC,sTrack,sType,sStagger,sGo,sStart,sDist,sFrames,sX1)
	{
	//trace("ease>    sMC:"+sMC);
	this._track=sTrack;
	this._mc=sMC;
	//trace("eTracks:"+sMC.eTracksMC);
	//	
	if(sMC.eTracksMC.valid!=true)
		{
		var __tgt=sMC.eTracksMC=sMC.createEmptyMovieClip("eTracksMC1",10000);
		this.mc_tracks=__tgt;
		__tgt.valid=true;
		__tgt.easeArr=new Object();
		__tgt.tgt_mc=sMC;
		//-----
		__tgt.updateTracks=function()
			{
			this.cnt=0;
			//
			for(var idx in this.easeArr)
				{
				this.cnt++;
				tgt=this.easeArr[idx];
				//
				if(tgt._go==true)
					{
					tgt._cFrame++;
					//
					if(tgt._cFrame<tgt._frames+1)
						{
						//-----
						val=easeVal(tgt._type,tgt._cFrame,tgt._dist,tgt._frames,tgt._sX1);
						//trace(idx);
						//
						if(idx!="#")
							{
							this.tgt_mc[tgt._track]=tgt._start+val;
							}
						//
						else
							{
							this.easeArr[idx]._par_pnt.useNum(tgt._start+val);
							}
						//
						if(tgt._cFrame==tgt._stagger)
							{
							tgt._par_pnt.staggerAction();
							}
						}
					//
					else
						{
						//delete tgt; doesn't delete what tgt points to! use delete this.easeArr[idx];
						x=tgt._par_pnt.easeAction;//reference with var x what function to call
						//
						if(idx=="#")
							{
							this._par_pnt.useNum=function(){};
							}
						delete this.easeArr[idx];//don't delete tgt, because it is only a reference and this.easeArr[idx] will still exist
						//
						if(x!=undefined)
							{
							x();//add () to call the referenced function AFTER deleting the array item above so it won't exist in the loop
							}
						}
					}
				}
			//
			if(this.cnt==0){this.onEnterFrame=function(){};}
			}
		}
	x=sMC.eTracksMC.easeArr;
	tgtTr=x[sTrack]=new Object();
	tgtTr._cFrame=-1;
	tgtTr._dist=sDist;
	tgtTr._frames=sFrames;
	tgtTr._go=sGo;
	tgtTr._par_pnt=this;
	tgtTr._stagger=sStagger;
	tgtTr._sX1=sX1;
	tgtTr._start=sStart;
	tgtTr._track=sTrack;
	tgtTr._type=sType;
	//
	sMC.eTracksMC.onEnterFrame=function()
		{
		//trace("*");
		this.updateTracks();
		}
	}
easeFormulas.as

Code: Select all

//easeFormulas.as
//by Kristoffe Brodeur 06-26-2006
//formulas referenced by Robert Penner
//----------
function easeLinear(t,c,d)
	{
	a2=(c/d)*t;
	return a2;
	}//f(easeLinear)
//----------
function easeInBack(t,c,d,s)
	{
	if(s==undefined){s=1.70158;}//if
	//default s=1.70158=10% overshoot in radiians
	//s=0 no overshoot	
	t=t/d;
	a2=c*t*t*((s+1)*t-s);
	return a2;
	}//f(easeInBack)
//----------
function easeOutBack(t,c,d,s)
	{
	if(s==undefined){s=1.70158;}//if
	t=t/d-1;
	a2=c*(t*t*((s+1)*t+s)+1);	
	return a2;
	}//f(easeOutBack)
//----------
function easeInQuad(t,c,d)
	{
	t=t/d;
	a2=c*t*t;
	return a2;
	}//f(easeInQuad)
//----------
function easeOutQuad(t,c,d)
	{
	t=t/d;
	a2=-c*t*(t-2);
	return a2;
	}//f(easeOutQuad)
//----------
function easeInOutQuad(t,c,d)
	{
	t=t/(d/2);
	if(t<1){a2=c/2*t*t;return a2;}//if
	else{a2=-c/2*((--t)*(t-2)- 1);return a2;}//else
	}//f(easeInOutQuad)
//----------
function easeInElastic(t,c,d,a,p)
	{
	//from penner if t==0, he has b as the base of your animation start
	//i dont use it in the formula, so i return 0, as there is NO b in my formulas
	//a2=0 would have been a2=b
	//return c would have been return b+c
	//if [p]period is 0, nothing really happens
	if(t==0){a2=0;return a2;}//if
	t=t/d;
	if(t==1){a2=c;return a2;}//if
	if(!p){p=d*.3;}//if
	if(a<Math.abs(c)){a=c;s=p/4;}//if
	else{s=p/(2*Math.PI)*Math.asin(c/a);}//else
	t--;
	a2=-(a*Math.pow(2,10*t)*Math.sin((t*d-s)*(2*Math.PI)/p));
	return a2;
	}//f(easeInElastic)
//----------
function easeOutElastic(t,c,d,a,p)
	{
	if(t==0){a2=0;return a2;}//if
	t=t/d;
	if(t==1){a2=c;return a2;}//if
	if(!p){p=d*.3;}//if
	if(a<Math.abs(c)){a=c;s=p/4;}//if
	else{s=p/(2*Math.PI)*Math.asin(c/a);}//else
	a2=a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c;	
	return a2;
	}//f(easeOutElastic)
//----------
function easeInBounce(t,c,d)
	{
	a2=c-easeOutBounce(d-t,c,d);
	return a2;
	}//f(easeInBounce)
//----------
function easeOutBounce(t,c,d)
	{
	t=t/d;
	if(t<(1/2.75))
		{
		a2=c*(7.5625*t*t);return a2;
		}
	else if(t<(2/2.75))
		{
		t=t-(1.5/2.75);
		a2=c*(7.5625*t*t+.75);return a2;
		}
	else if(t<(2.5/2.75))
		{
		t=t-(2.25/2.75);
		a2=c*(7.5625*t*t+.9375);return a2;
		}
	else
		{
		t=t-(2.625/2.75);
		a2=c*(7.5625*t*t+.984375);return a2;
		}
	}//f(easeOutBounce)
createMovieClip2.as

Code: Select all

//createMovieClip2.as v10.0 12-15-2008
//By Kristoffe Brodeur.
//03-2005
//07-2005
//09-2005
//03-28-2006
//05-25-2006 -zoom scale initialization to beg
//06-19-2006 TimerA
//07-08-2006 a=RGB2HEX_2("255:255:255")->a="0xFFFFFF"
//09-10-2006 alignClip for quick object alignment to a larger parent object's limits
//09-12-2006 colorMorph2 - now a string "11:209:100" can be sent as colorA and colorB / + Number(*) to change strings to Int/Float
//10-05-2006 MovieClip.prototype.loadMC : f*loadAction=...||filename(.swf|.jpg|.png)
//12-09-2006 fixed loadMC to COPY loadAction, not just point to it. Created an Object fnctClone, then a property loadAction by copying
//12-25-2006 added sentLevel to timerA OBJ
//12-28-2006 added oopPar so a movieclip can reference its object oriented target after loading for loadAction pointing etc
//03-10-2007 fixed p1 as pl in one instance. 1 and l look a lot alike
//03-27-2007 rebuilt loadMC with deepCopy property duplication. after loading, new MC has all of old MC's props and methods.
//06-09-2007 MovieClip.prototype.propScale (maxW,maxH) now the MC can resize itself
//08-19-2008 Added name+depth to createEM so the new empty clips wouldnt overwrite themselves because of exact same names on given root
//12-15-2008 Reviewed TimerA and made it not rely on a MC
//01-04-2008 draw_rect on a sent object and it's width and height, and of course color
//-----
function draw_rect(sObj,w,h,sColor,sAlpha,xOff,yOff)
	{
	//trace(sObj+newline+w+":"+h+":("+sColor+"):"+sAlpha+":"+xOff+":"+yOff);
	//color 0xFFFFFF R G B
	//offsets are not neccessary to draw a rectangle
	if(xOff==undefined){xOff=0;};
	if(yOff==undefined){yOff=0;};
	if(sAlpha==undefined){sAlpha=100;};
	sObj.beginFill(sColor,sAlpha);
	sObj.moveTo(0+xOff,0+yOff);
	sObj.lineTo(0+xOff+w,0+yOff);
	sObj.lineTo(0+xOff+w,0+yOff+h);
	sObj.lineTo(0+xOff,0+yOff+h);
	sObj.lineTo(0+xOff,0+yOff);
	sObj.endFill();
	}
//----------
MovieClip.prototype.propScale=function(maxW,maxH)
	{
	//trace("++++++++++++++++++propScale:"+maxW+":"+maxH);
	this._xscale=100;
	this._yscale=100;
	origW=this._width;
	origH=this._height;
	//------------------------------------------------------------
	if((origH/maxH)>(origW/maxW))
		{
		this._height=maxH;
		this._width=(maxH/origH)*origW;
		}//if
	//------------------------------------------------------------
	if((origH/maxH)<(origW/maxW))
		{
		this._width=maxW;
		this._height=(maxW/origW)*origH;
		}//if		
	//------------------------------------------------------------
	if((origH/maxH)==(origW/maxW))
		{
		this._width=maxW;
		this._height=maxH;
		}//if	
	}
//----------
MovieClip.prototype.loadMC=function(filename)
	{
	//tF_debug.text+=newline+"loadMC("+filename+")";
	//first, use the parent of this MC and make a holder for all of the MC's properties and methods
	//when you load a movieclip, it all gets lost anyway, so this allows a transfer from temp back to loaded MC
	p1=this._parent;//_root
	n1=this._name;//mc_placer
	l1=n1+"_ldr";//mc_placer_ldr
	//loadMC main placer for all subclips.
	//each loading MC will have a temp method and property hold on this p1._lMCPar
	if(!p1._lMCPar)
		{
		p1.createEmptyMovieClip("_lMCPar",10000);
		//trace("[p1._lMCPar]"+p1._lMCPar);
		}	
	nxtD=p1._lMCPar.getNextHighestDepth();
	tmpObj=p1._lMCPar.createEmptyMovieClip("_ldr"+nxtD,nxtD);
	tmpObj.objCopy=new Object();
	//
	for(var p in this)
			{
			tmpObj.objCopy[p]=this[p];	
			}	
	tmpObj.ldr=new MovieClipLoader();
	tmpObj.ldr.pnt=tmpObj.objCopy;
	tmpObj.ldr.onLoadInit=function(mc)
		{
		//tF_debug.text+=newline+"LOADED!";
		//
		for(var p in this.pnt)
			{
			mc[p]=this.pnt[p];
			}
		mc.loadAction();
		}

	tmpObj.ldr.loadClip(filename,this);
	}
//----------
function alignClip(sentRoot,sentMC,sentAlignX,sentAlignY)
	{
	X1=sentRoot._x;
	X1W=sentRoot._width;
	X2=sentMC._width;
	Y1=sentRoot._y;
	Y1H=sentRoot._height;
	Y2=sentMC._height;
	//trace("[root]"+sentRoot+newline+"[MC]"+sentMC);
	//trace("[X1]"+X1+"[X1W]"+X1W+"[X2]"+X2+"<"+sentAlignX+">");
	//trace("[Y1]"+Y1+"[Y1H]"+Y1H+"[Y2]"+Y2+"<"+sentAlignY+">");
	if(sentAlignX=="left")
		{
		newX=X1;
		}
	if(sentAlignX=="center"||sentAlignX=="c")
		{
		//trace("CENTER!");
		newX=X1+(X1W-X2)/2;
		}
	//
	if(sentAlignX=="right"||sentAlignX=="r")
		{
		newX=X1+X1W-X2;
		}
	if(sentAlignY=="top"||sentAlignY=="t")
		{
		newY=Y1;
		}
	//
	if(sentAlignY=="center"||sentAlignY=="c")
		{
		newY=Y1+(Y1H-Y2)/2;
		}
	if(sentAlignY=="bottom"||sentAlignY=="b")
		{
		newY=Y1+Y1H-Y2;
		}
	sentMC._x=Math.floor(newX);
	sentMC._y=Math.floor(newY);
	}	
//----------
function TimerA(sentObj,sentDur,sentLevel)
	{
	//trace("timer"+sentObj+":"+sentDur+":"+sentLevel);
	//
	if(!sentLevel)
		{
		sentLevel=0;
		}
	this.time1=new createEM(sentObj,"_timer_",30000+sentLevel,0,0);
	tgt1=this.time1.inst;
	tgt1.frame=-1;
	tgt1.dur=sentDur;
	tgt1.par=this;
	tgt1.onEnterFrame=function()
		{
		this.frame++;
		//trace(this.frame);
		//
		if(this.frame==this.dur)
			{
			this.onEnterFrame=function(){};
			//trace("finished timer");
			this.par.timerAction();
			}
		}
	}
//-------------------------------------------------------------------------
function glowObj(mcObj,frameRate)
	{
	//-----
	mcObj.fadeInAction=function()
		{
		fadeOutClip(this,this.frameRate);
		}//f()
	//-----
	mcObj.fadeOutAction=function()
		{
		fadeInClip(this,this.frameRate);
		}//f()
	//-----
	fadeInClip(mcObj,frameRate);
	mcObj.frameRate=frameRate;
	}
//-------------------------------------------------------------------------
function moveClipTo(mcObj,toX,toY,totalFrames)
	{
	trace("moveClipTo");
	mcObj.beg_x=mcObj._x;
	mcObj.beg_y=mcObj._y;
	mcObj.end_x=toX;
	mcObj.end_y=toY;
	mcObj.tFrames=totalFrames;
	mcObj.currFrame=-1;
	mcObj.rate_x=(mcObj.end_x-mcobj.beg_x)/2;
	mcObj.rate_y=(mcObj.end_y-mcobj.beg_y)/2;
	mcObj.onEnterFrame=function()
		{
		this.currFrame+=1;
		//
		if(this.currFrame==this.tFrames)
			{
			this.moveToAction();
			}//if
		else
			{
			this._x+=this.rate_x;
			this._y+=this.rate_y;
			}//else
		}//f(onEnterFrame)
	}//f(moveClipTo)
//-------------------------------------------------------------------------
function zoomClip(mcObj,zoom_beg,zoom_end,zoom_amt)
	{
	mcObj._xscale=zoom_beg;
	mcObj._yscale=zoom_beg;
	mcObj.zBeg=zoom_beg;
	mcObj.zEnd=zoom_end;
	mcObj.zSpeed=zoom_amt;
	len=mcObj.zBeg-mcObj.zEnd;
	mcObj.div=len/mcObj.zSpeed;
	mcObj.divCnt=-1;
	mcObj.onEnterFrame=function()
		{
		this.divCnt+=1;
		//
		if(this.divCnt!=this.zSpeed)
			{
			this._xscale-=this.div;
			this._yscale=this._xscale;
			}//if
		//
		else
			{
			this.onEnterFrame=function(){};
			this.zoomAction();
			}//else
		}//f()
	}//f(zoomClip)
//-------------------------------------------------------------------------
function fadeInClip(mcObj,frameRate,sent_fadeTo)
	{
	//
	if(sent_fadeTo)
		{
		//trace("[fadeTo]"+sent_fadeTo);
		//
		if(sent_fadeTo==100)
			{
			sent_fadeTo=99;
			}
		mcObj.fadeTo=sent_fadeTo;
		mcObj.fRate=frameRate;
		}//if
	else
		{
		mcObj.fadeTo=99;
		}//else
	//
	mcObj.onEnterFrame=function()
		{
		//trace("[]"+this._alpha+":"+this.fadeTo);
		//
		if(this._alpha<this.fadeTo)
			{
			//
			if(this._alpha+this.fRate<=99)
				{
				//trace("[adding]");
				this._alpha+=this.fRate;
				}
			else
				{
				//trace("[alpha=99]");
				this._alpha=99.9;
				}
			}//if
		//
		else
			{
			this.onEnterFrame=function(){};
			this.fadeInAction();
			}//else
		}//f()
	}//f()
//-------------------------------------------------------------------------
function fadeOutClip(mcObj,frameRate,sent_fadeTo)
	{
	//trace("FADEOUT!");
	//
	if(sent_fadeTo)
		{
		mcObj.fadeTo=sent_fadeTo;
		}//if
	else
		{
		mcObj.fadeTo=0;
		}//else
	//
	mcObj.onEnterFrame=function()
		{
		//
		if(this._alpha>this.fadeTo)
			{
			this._alpha-=frameRate;
			}//if
		//
		else
			{
			this.onEnterFrame=function(){};
			this.fadeOutAction();
			}//else
		}//f()
	}//f()
//----------
function createMC(sPar,sLibName,newObj,sLayer,sX,sY,sRot,sWidth,sHeight,vis)
	{
	//trace("//----------");
	this.libName=sLibName;
	this.mcName=newObj;
	this.depth=sLayer;
	this.newObjName=newObj+sLayer;
	var newMC=sPar.attachMovie(sLibName,this.newObjName,sLayer);
	this.instance=this.inst=newMC;
	//trace("[createMC][inst]"+this.inst+":");
	//trace("[sParent]"+sPar);
	//trace("[sLibName]"+sLibName);
	//trace("[sLayer]"+sLayer);
	//trace("[newObj]"+this.newObjName);
	//
	if(sWidth>0)
		{
		this.inst._width=sWidth;	
		}//if
	//
	if(sHeight>0)
		{
		this.inst._height=sHeight;			
		}//if
	//
	if(vis==1)
		{
		this.inst._visible=false;
		}//if
	this.inst._x=sX;
	this.inst._y=sY;
	//newMC._rotation=sRot;
	//rotateObj(newMC,0);
	newMC._rotation=sRot;
	rotateObj(newMC,0);
	}//f()
//----------
createMC.prototype.resetScale=function()
	{
	this.instance._xscale=100;
	this.instance._yscale=100;
	}//f()
//----------
function rotateObj(sentObj)
	{
	sentObj.rotate=function(amt)
		{
		//% means modulo 
		//12%5 means 12/5 rem 2
		//a=12%5=2
		realAngle=0;
		//
		if(this._rotation<0)
			{
			realAngle=360+this._rotation;
			}//f()
		else
			{
			realAngle=this._rotation;
			}//else
		newAngle=realAngle+amt;
		//
		if(newAngle>360||newAngle<360)
			{
			newAngle=newAngle%360;
			}//f()
		//trace(amt+":"+realAngle+":"+newAngle);
		//_rotation 0-180 is 0~180
		if(newAngle<180)
			{
			//do nothing
			}//if
		//_rotation 180-360 is -180~0
		if(newAngle>180)
			{
			newAngle=-(360-newAngle);
			}//if
		this._rotation=newAngle;
		}//f()		
	}//f()
//----------
function createEM(sParent,newObj,sDepth,sX,sY)
	{
	//remember to add sDepth to the new MC name or it will write the same object ontop of the next one coming in 
	newEM=sParent.createEmptyMovieClip(newObj+sDepth,sDepth);
	this.instance=this.inst=newEM;
	//trace("[EM]"+this.inst);
	this.inst._x=sX;
	this.inst._y=sY;
	}//f()
//---------------------------------------------------------------------------
function colorCycle(mcObj,sentColors,sentAmt,sentRate)
	{
	//trace(sentColors);
	//trace("[colorCycle]");
	mcObj.colorAmt=sentAmt;
	mcObj.cArray=sentColors;
	mcObj.fRate=sentRate;
	mcObj.cyclePos=-1;
	mcObj.cC_step=0;
	mcObj.cMorphAction=function()
		{
		this.cyclePos++;
		trace("[+1]------------------------"+this.cyclePos);
		//
		switch(true)
			{
			case this.cyclePos<this.cArray.length-1:
				{
				trace("[c]<len:"+this.cArray[this.cyclePos]+":"+this.cArray[this.cyclePos+1]);
				colorMorph2(this,this.cArray[this.cyclePos],this.cArray[this.cyclePos+1],this.colorAmt,this.fRate);
				break;
				}//case
			case this.cyclePos==this.cArray.length-1||(this.cArray.length==2&&this.cyclePos==2):
				{
				trace("[c]==len:"+this.cArray[this.cyclePos]+":"+this.cArray[0]);
				tPos=this.cyclePos;
				this.cyclePos=-1;
				colorMorph2(this,this.cArray[tPos],this.cArray[0],this.colorAmt,this.fRate);
				break;
				}//case
			}//switch
		}//f()
	mcObj.cMorphAction();
	}//f()
//-------------------------------------------------------------------------
function colorMorph2(mcObj,colorA,colorB,colorAmt,frameRate)
	{
	//colors can now be a string "11:43:200" for colorA and colorB
	//
	x1=colorA.split(":");
	mcObj.machine=new createEM(mcObj,"cM_machine",0,0);
	ptr=mcObj.machine.instance;
	a=colorA.split(":");
	b=colorB.split(":");
	ptr.colA=new Array();
	ptr.colB=new Array();
	//
	for(c=0;c<a.length;c++)
		{
		ptr.colA[c]=Number(a[c]);
		ptr.colB[c]=Number(b[c]);
		}
	ptr.cAmt=colorAmt;
	ptr.frameRate=frameRate;
	ptr.cStep=0;
	ptr.cMA=new Array(0,0,0);	
	ptr.onEnterFrame=function()
		{
		cFrac=0;
		//
		if(this.cStep<100)
			{
			this.cStep+=this.frameRate;
			cFrac=this.cStep/100;
			//
			for(g=0;g<3;g++)
				{
				//Number(*) changes a string to a Number Int of Float
				diff=Number(this.colB[g])-Number(this.colA[g]);
				scaled=diff*cFrac;
				newTotal=Number(this.colA[g])+scaled;
				this.cMA[g]=newTotal;
				}//for(g)
			//trace(this.cMA);
			colorTint(this._parent,this.cMA,this.cAmt);
			}//if
		//
		else
			{
			this.onEnterFrame=function(){};
			this._parent.cMorphAction();
			}//else
		}//f()
	}//f()
//-------------------------------------------------------------------------
function colorMorph(mcObj,colorA,colorB,colorAmt,frameRate)
	{
	//trace("[cMorph] A:"+colorA+"     B:"+colorB);
	//
	mcObj.machine=new createEM(mcObj,"cM_machine",0,0);
	ptr=mcObj.machine.instance;
	ptr.colA=colorA;
	ptr.colB=colorB;
	ptr.cAmt=colorAmt;
	ptr.cStep=0;
	ptr.cMA=new Array(0,0,0);	
	ptr.onEnterFrame=function()
		{
		//trace("cS:"+this.cStep);
		//
		if(this.cStep<100)
			{
			this.cStep+=frameRate;
			cFrac=this.cStep/100;
			//
			for(g=0;g<3;g++)
				{
				this.cMA[g]=this.colA[g]+((this.colB[g]-this.colA[g])*cFrac);
				//trace("["+g+"]"+this.cMA[g]);
				}//for(g)
			colorTint(this._parent,this.cMA,this.cAmt);
			}//if
		//
		else
			{
			this.onEnterFrame=function(){};
			this._parent.cMorphAction();
			}//else
		}//f()
	}//f()
//---------------------------------------------------------------------------
function colorTint2(sentObj,sentColorString,sentAmt)
	{
	//trace("sentObj:"+sentObj+":sentColorString>"+sentColorString+":sentAmt>"+sentAmt);
	tmpClr=sentColorString.split(":");
	//trace(tmpClr);
	newT=new Object();
	newT.ra=newT.ga=newT.ba=100-sentAmt;
	var cRatio=sentAmt/100;
	newT.rb=Number(tmpClr[0])*cRatio;
	newT.gb=Number(tmpClr[1])*cRatio;
	newT.bb=Number(tmpClr[2])*cRatio;
	//trace(newT.rb+":"+newT.gb+":"+newT.bb);	
	cObj=new Color(sentObj);
	cObj.setTransform(newT);
	//trace("colotTint2>finished!");
	}//f(colorTint)
//---------------------------------------------------------------------------
function colorTint(sentObj,sentColorArray,sentAmt)
	{
	newT=new Object();
	newT.ra=newT.ga=newT.ba=100-sentAmt;
	var cRatio=sentAmt/100;
	newT.rb=sentColorArray[0]*cRatio;
	newT.gb=sentColorArray[1]*cRatio;
	newT.bb=sentColorArray[2]*cRatio;
	cObj=new Color(sentObj);
	cObj.setTransform(newT);
	}//f(colorTint)
//---------------------------------------------------------------------------
function Colorize(sentObj,sentColorArray)
	{
	//*.rC  *.gC  *.bC  in sentColotArray
	newC=new Color(sentObj);
	//trace(sentObj+":"+sentColorArray);
	//trace(RGB2HEX(sentColorArray));
	newC.setRGB(RGB2HEX(sentColorArray));
	}//f()
//----------
//a=RGB2HEX_2("100:112:35");->a=0x647023 string;
//----------
function RGB2HEX_2(sentString)
	{
	tmpHex="0x";
	tmpRGB=sentString.split(":");
	//trace(tmpRGB);
	//
	for(rgb1=0;rgb1<3;rgb1++)
		{
		tmp1=parseInt(tmpRGB[rgb1]);
		tmp2=tmp1.toString(16);
		if(tmp2.length<2)
			{
			tmp2="0"+tmp2;
			}
		tmpHex+=tmp2;
		}
	return(tmpHex);
	}
//----------
function RGB2HEX(cObj)
	{
	//---------------------------------------------------------------------------
	if(cObj)
		{
		//sCArray is a RGB color array with 0-255
		//toString(16) creates a string version of hex 00~FF
		//---------------------------------------------------------------------------
		if(cObj.rC&&cObj.bC&&cObj.gC)
			{
			var tempHex=new Array(cObj.rC.toString(16),cObj.bC.toString(16),cObj.gC.toString(16));
			}//if
		//---------------------------------------------------------------------------
		if(cObj.length==3)
			{
			var tempHex=new Array();
			//
			for(tA=0;tA<3;tA++)
				{
				tempHex[tA]=cObj[tA].toString(16);
				}//for(tA)
			}//if
		var finalHex="";
		var realHex=0xFFFFFF;
		//---------------------------------------------------------------------------
		for(rgbA=0;rgbA<3;rgbA++)
			{
			//
			if(tempHex[rgbA].length<2)
				{
				tempHex[rgbA]="0"+tempHex[rgbA];
				}//if
			finalHex=finalHex+tempHex[rgbA];
			finalHex=finalHex.toUpperCase();
			}//for(rgbA)
		realHex=parseInt(finalHex,16);
		return realHex;
		}//if()
	}//f()
//--------------------------------------------------------------------------------------------
function limitResize(sent_LimW,sent_LimH,orig_w,orig_h)
	{
	//------------------------------------------------------------
	if(!destProp)
		{
		destProp=new Object();
		}//if
	//------------------------------------------------------------
	if((orig_h/sent_LimH)>(orig_w/sent_LimW))
		{
		destProp.h=sent_LimH;
		destProp.w=(sent_LimH/orig_h)*orig_w;
		}//if
	//------------------------------------------------------------
	if((orig_h/sent_LimH)<(orig_w/sent_LimW))
		{
		destProp.w=sent_LimW;
		destProp.h=(sent_LimW/orig_w)*orig_h;
		}//if		
	//------------------------------------------------------------
	if((orig_h/sent_LimH)==(orig_w/sent_LimW))
		{
		destProp.w=sent_LimW;
		destProp.h=sent_LimH;
		}//if
	return(destProp);
	}//f(limitResize)
//--------------------------------------------------------------------------------------------
function alignMC(sentChild,sentTarget)
	{
	sentChild._x=sentTarget._x;
	sentChild._y=sentTarget._y;
	}//f(alignMC)
Post Reply