3

我只是想知道是否可以在 adobe flex 中暂停正在播放的 SWF 文件?我有一个 SWF 加载程序,它可以播放我的 SWF 文件,但是它没有任何暂停文件的功能(或内置功能)。

任何人都可以帮我解决这个问题吗?我会很感激一些代码开始。:) 提前致谢。

4

1 回答 1

1

您可以使用stop();

下面是一个 swf 播放的示例,并控制了 play 和 pause 和 gotoandstop 按钮。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            private function playHandler():void {

                var file_mc:MovieClip = fileswf.content as MovieClip;
                file_mc.play();

            }

            private function pauseHandler():void {

                var file_mc:MovieClip = fileswf.content as MovieClip;
                file_mc.stop();
            }

            private function pauseat(frame:Number):void {

                var file_mc:MovieClip = fileswf.content as MovieClip;
                file_mc.gotoAndStop(frame);
            }

        ]]>
    </fx:Script>


    <mx:SWFLoader x="0" y="0" source="abc.swf" id="fileswf"/>
    <s:Button x="0" y="200" label="Play" id="playbtn" click="playHandler()"/>
    <s:Button x="100" y="200" label="Pause" id="pausebtn" click="pauseHandler()"/>
    <s:Button x="100" y="250" label="Pause at A" id="pauseAbtn" click="pauseat(1)"/>
    <s:Button x="200" y="250" label="Pause at B" id="pauseBbtn" click="pauseat(2)"/>
    <s:Button x="300" y="250" label="Pause at C" id="pauseCbtn" click="pauseat(3)"/>
    <s:Button x="400" y="250" label="Pause at D" id="pauseDbtn" click="pauseat(4)"/>
    <s:Button x="500" y="250" label="Pause at E" id="pauseEbtn" click="pauseat(5)"/>

</s:Application>

为了完整起见,我在 @Embed 的方法中放置了(无法通过 SWFLoader [运行时与编译时] 直接获取原始 swf,但您可以从类中加载字节)

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955" minHeight="600" addedToStage="init()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[

            [Embed(source="abc.swf", mimeType="application/octet-stream") ]
            public var abc_cls:Class;

            public var ldr:Loader = new Loader();

            private var file_mc:MovieClip;

            protected function init():void
            {
                ldr.loadBytes( new abc_cls() as ByteArray );
                ldr.contentLoaderInfo.addEventListener(Event.INIT, onSwfLoaded);
                swfcontainer.addChild(ldr);  
            }

            private function onSwfLoaded(e:Event):void {
                file_mc = ldr.content as MovieClip;
            }

            private function playHandler():void {

                file_mc.play();

            }

            private function pauseHandler():void {

                file_mc.stop();
            }

            private function pauseat(frame:Number):void {


                file_mc.gotoAndStop(frame);
            }       

        ]]>
    </fx:Script>


    <mx:Image id="swfcontainer" />
    <s:Button x="0" y="200" label="Play" id="playbtn" click="playHandler()"/>
    <s:Button x="100" y="200" label="Pause" id="pausebtn" click="pauseHandler()"/>
    <s:Button x="100" y="250" label="Pause at A" id="pauseAbtn" click="pauseat(1)"/>
    <s:Button x="200" y="250" label="Pause at B" id="pauseBbtn" click="pauseat(2)"/>
    <s:Button x="300" y="250" label="Pause at C" id="pauseCbtn" click="pauseat(3)"/>
    <s:Button x="400" y="250" label="Pause at D" id="pauseDbtn" click="pauseat(4)"/>
    <s:Button x="500" y="250" label="Pause at E" id="pauseEbtn" click="pauseat(5)"/>

</s:Application>

I am sure now that it is the embed that was giving the problem sorry for any confusions. So if you need your swf as part of your file below should the trick.

The last way you can achieve getting assets into your flex workspace is to use SWC Assets Method.

Good Luck ! :D

于 2010-06-09T07:24:47.257 回答