脱离时间表,接受一些基本的组织结构,是你作为穿透闪光的制作者、节目制作者或认真的学生所能做的唯一最佳事情。 它可以是一个深层的主题,但越早,越早,越早越好。 狗将解释一切。
不管怎么说,你大多数需要将这一程序写进一个班级。 简要解释说明:
// package encloses the class and identifies its scope
package you.com.app
{
//imports
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.TextField;
/**
* ... declare your class, whatever it may extend and any interfaces
*/
public class MediaPlayer extends Sprite
{
// variables now include an access modifier to define their scope (private, here)
private var xml :XML;
private var amountofvid :Number=0;
private var currentvideo :Number=0;
private var loader :URLLoader;
private var vid :MovieClip; //or video component or whatever
private var title :TextField;
private var btn_prev :SimpleButton;
private var btn_next :SimpleButton;
private var currentvideo :int;
/**
* constructor - must match class name. returns statement omitted
*/
public function MediaPlayer()
{
// call superclass
super();
//initialize procedure
init();
}
private function init():void
{
//build display list
assembleDisplayObjects();
//grab data
retreiveData();
}
private function retreiveData():void
{
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlloaded);
loader.load(new URLRequest( videos.xml ));
}
private function xmlloaded (e:Event):void
{
xml = new XML();
xml=XML(e.target.data);
amountofvid=xml.video.length ()-1;
changevid();
addEventHandlers(); //when data has loaded, activate clickables
}
private function assembleDisplayObjects():void
{
// create or instantiate display objects, and into the display list
// adjust x,y values as needed
vid = new MovieClip();
this.addChild(vid);
title = new TextField();
this.addChild(title);
btn_next = new SimpleButton();
this.addChild(btn_next);
btn_prev = new SimpleButton();
this.addChild(btn_prev);
}
private function addEventHandlers():void
{
//centralized event listener control
btn_prev.addEventListener (MouseEvent.CLICK, prevvid);
btn_next.addEventListener (MouseEvent.CLICK, nextvid);
}
private function nextvid (e:Event):void
{
currentvideo++;
changevid();
}
private function prevvid (e:Event):void
{
currentvideo--;
changevid();
}
private function changevid():void
{
var cv:Number=Math.abs(currentvideo);
if (cv>amountofvid) {
currentvideo=cv=0;
}
if (currentvideo<0) {
currentvideo=cv=amountofvid;
}
vid.source = xml.video.@src[cv];
title.text = xml.video.@title[cv];
}
}
}
我先验了这一点,也许不会错过,但这是基本的一揽子/等级结构,应当让你去。
我高度建议Shupe /Rosers“学习行动文件3.0”,将其作为这个主题的重要内容,而Mook s “Esential Actionscript 3.0”作为全面参考。 And google. go。
Hope that helps.