[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Actionscript functions

Asked by thomasmutton in ActionScript, Adobe Flash

Tags: actionscript, functions

Hello there,

I have some code that on its own plays videos. I would now like to put all of this code within one function to call it whenever I want.

I have tried to put it inside its own function but it wont work :(

Can anyone advise on what to do here? Is it that functions cant contain functions?

Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
videos();
 
function videos():Void
{
	// All Matts Stuff below here...
	
	//initialise vars
	var nDownload:Number;
	var nPlayback:Number;
	var totalLength:Number;
	var currentVideo:Number = 0;
	var totalVideos:Number;
	var paused:Boolean = false;
	var movieEnded:Boolean;
	var aVideos:Array = new Array();
	
	//load xml file
	var videoXML:XML = new XML();
	videoXML.ignoreWhite = true;
	var rootNode:XMLNode;
	var currNode:XMLNode;
	videoXML.onLoad = function():Void
	{
		rootNode = this.firstChild;
		for (var i:Number = 0; i < rootNode.childNodes.length; i++) 
		{
			currNode = rootNode.childNodes[i];
			aVideos.push({source:currNode.attributes["tvad_filename"], title:currNode.attributes["tvad_title"],description:currNode.attributes["description"]});
		}
		totalVideos = aVideos.length;
		populateList();
	};
	videoXML.load("Data/videos.xml");
	
	
	//lets get the functions out of the way....
	var cList:Object = mcTab.mcPlaylist.cList;
	cList.vScrollPolicy = "auto";
	var listListener:Object = new Object();
	cList.addEventListener("change", listListener);
	listListener.change = function() 
	{
		var index:Number = cList.selectedIndex;
		currentVideo = index;
		populateFields(index);
		playVideo(aVideos[index].source);
	};
	function populateList():Void 
	{
		for (var i:Number = 0; i<totalVideos; i++)
		{
			cList.addItem(aVideos[i].title);
		}
		cList.selectedIndex = currentVideo;
		populateFields(0);
		playVideo(aVideos[0].source);
	}
	
	
	//this is where you can access the xml data easily
	function populateFields(index:Number):Void
	{
		_root.tTitle.text = "TV COMMERCIALS " + aVideos[index].title;
	}
	
	
	//stuff to connect to video and set up buffer
	var nc:NetConnection = new NetConnection();
	nc.connect(null);
	var ns:NetStream = new NetStream(nc);
	ns.setBufferTime(5);
	mcVideo.oVideo.attachVideo(ns);
	function playVideo(video:String):Void
	{
		movieEnded = false;
		mcBuffer._visible = true;
		clearIntervals();
		ns.play(video);
		nDownload = setInterval(downloadProgress, 1000/24);
		nPlayback = setInterval(playback, 1000/24);
	}
	
	
	//this bit checks what is happening with the playback
	ns.onStatus = function(oInfo:Object):Void 
	{
		trace(oInfo.code);
		//check if the movie has started
		if (oInfo.code == "NetStream.Play.Start")
		{
			trace("movie has started");
		}
		///check if the movie has finished
		if (oInfo.code == "NetStream.Play.Stop")
		{
			//if it has stopped, goto next one.
			currentVideo++;
			progressbar = true;
			playVideo(aVideos[currentVideo].source);
			populateFields(currentVideo);
			//check to see if we're on the last video
			//if we are
			if (currentVideo == totalVideos)
			{
				//original block of code
				//add what you wanna do after all the vids have been looped through
				_root.attachMovie("introTVCs_mc", "introTVCs_mc", 1, {_x: 0, _y: 0});
				//in this block dude :)
				trace("movie ended");
				
				clearInterval(nPlayback);
				movieEnded = true;
				mcBuffer._visible = false;
				
			}
			//videos();
		}
		//and if the source file can't be found?
		if (oInfo.code == "NetStream.Play.StreamNotFound")
		{
			trace("movie cannot be found");
		}
		if (oInfo.code == "NetStream.Buffer.Full")
		{
			mcBuffer._visible = false;
		}
		if (oInfo.code == "NetStream.Buffer.Empty" && !movieEnded)
		{
			trace("buffer empty");
			mcBuffer._visible = true;
			// buffer is empty now we need to check if remaining movie time is less buffer requirement
			var timeRemaining:Number = totalLength-ns.time;
			if (timeRemaining<ns.bufferTime)
			{
				ns.setBufferTime(timeRemaining);
			}
		}
	};
	ns["onMetaData"] = function (oInfo:Object):Void
	{
		totalLength = oInfo.duration;
	};
	
	//just to check how quickly it buffered
	trace(ns.bufferTime);
	
	//check how much has loaded and update status bar if needed
	var nBytesLoaded:Number;
	var nBytesTotal:Number;
	var percentageLoaded:Number;
	function downloadProgress():Void
	{
		nBytesLoaded = ns.bytesLoaded;
		nBytesTotal = ns.bytesTotal;
		percentageLoaded = nBytesLoaded/nBytesTotal*100;
		mcProgressBar.mcDownloadBar._xscale = percentageLoaded;
		if (percentageLoaded == 100)
		{
			clearInterval(nDownload);
		}
	}
	
	//just in case
	function clearIntervals():Void
	{
		clearInterval(nDownload);
		clearInterval(nPlayback);
	}
}
[+][-]08/21/08 07:44 PM, ID: 22285902Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/22/08 01:36 AM, ID: 22287836Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/22/08 03:12 AM, ID: 22288180Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: ActionScript, Adobe Flash
Tags: actionscript, functions
Sign Up Now!
Solution Provided By: Proactivation
Participating Experts: 2
Solution Grade: A
 
[+][-]08/22/08 04:12 AM, ID: 22288460Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_2_20070628