English 中文(简体)
Covert to Actionscript 3级
原标题:Covert to Actionscript 3 Class

我在各种辅导材料之后,在行动说明3中制定了一些守则,这些辅导是媒体的一个简单角色,与用于信息来源的XML文件有关。 我发现,尽管我需要为守则使用行动说明课程,但我想知道,这些课程是将其转换为班级的一种方式,还是任何人都知道在行动说明3中为创建基于班级的媒体角色提供辅导吗? 我的法典如下:

import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,xmlloaded);

var xml:XML = new XML();
var amountofvid:Number=0;
var currentvideo:Number=0;

btn_prev.addEventListener (MouseEvent.CLICK, prevvid);
btn_next.addEventListener (MouseEvent.CLICK, nextvid);

loader.load(new URLRequest( videos.xml ));

function xmlloaded (e:Event) {
    xml=XML(e.target.data);
    amountofvid=xml.video.length ()-1;
    changevid();
}

function nextvid (e:Event) {
    currentvideo++;
    changevid();
}

function prevvid (e:Event) {
    currentvideo--;
    changevid();
}

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];

}

Any ideas?

最新消息,由于两条帮助的幌子都帮助了负荷工作,我可以请大家找到解决办法。

最佳回答

在这里,您的法典迅速改成一类。

package  {

import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;    

public class mediaPlayer extends Sprite {

    private var loader:URLLoader;
    private var xml:XML;
    private var amountofvid:Number=0;
    private var currentvideo:Number=0;

    public function mediaPlayer() {

        loader = new URLLoader();
        loader.addEventListener(Event.COMPLETE,xmlloaded);
        btn_prev.addEventListener (MouseEvent.CLICK, prevvid);
        btn_next.addEventListener (MouseEvent.CLICK, nextvid);
        loader.load(new URLRequest( videos.xml ));

    }

    private function xmlloaded (e:Event) {
        xml = new XML();
        xml=XML(e.target.data);
        amountofvid=xml.video.length()-1;
        changevid();
    }

    public function nextvid (e:Event) {
        currentvideo++;
        changevid();
    }

    public function prevvid (e:Event) {
        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];

    }

}

}

我假定,它会与一项展品有关,从而延伸到此。 如果你想把这个类别与其他类别联系起来,你将想改变这一行:

public class mediaPlayer extends Sprite {

我保持了下游和先发制人的方法的公开性(例如,你可以从另一个层面获得,也可以从另一个层面获得,也可以从另一个层面获得)。 你们可能希望改变这种状况,以满足你们的需要。

For a startup tutorial on how classes works, i would suggest this one on GoToAndLearn.com http://gotoandlearn.com/play.php?id=43

页: 1

问题回答

脱离时间表,接受一些基本的组织结构,是你作为穿透闪光的制作者、节目制作者或认真的学生所能做的唯一最佳事情。 它可以是一个深层的主题,但越早,越早,越早越好。 狗将解释一切。

不管怎么说,你大多数需要将这一程序写进一个班级。 简要解释说明:

// 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.





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

Red5 Security Tutorial

I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

visible property of DisplayObject

For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...

热门标签