像虚拟女孩一样使用flex播放swf文件

时间:2013-03-30 06:11:32

标签: flex air flex4.6

我正在开发Flex 4.6 Air应用程序,其中有一个列表,数据是透明的背景swf文件。我的问题是,当我双击列表项时,尊重的swf文件应该在后台播放,或者我们可以在桌面上说虚拟女孩应用程序。如果我们最小化主应用程序,swf应该像虚拟女孩应用程序一样在桌面上播放。

如果有人有任何想法请告诉我。

Thnank你这么多。

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码在双击列表项的情况下打开mx或spark窗口。

以下代码可能对您有用。

<?xml version="1.0" encoding="utf-8"?>
<s:Window xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:mx="library://ns.adobe.com/flex/mx"
          xmlns:customcomponents="customs.customcomponents.*"
          xmlns:services="services.*"
          width="100%" height="100%" backgroundAlpha="0"
          creationComplete="window1_creationCompleteHandler(event)" minimizable="false"
          showStatusBar="false" systemChrome="none" transparent="true"> 

    <fx:Script>
        <![CDATA[
            import air.net.URLMonitor;

            import dbconnection.Connection;

            import globalData.DataModel;

            import mx.collections.ArrayCollection;
            import mx.core.FlexGlobals;
            import mx.events.FlexEvent;
            import mx.utils.UIDUtil;

            import vo.UserSettingsVo;

            private var movie:MovieClip;
            private var movieTotalFrame:int = 0;
            public var countMovie:int = 0;          
            public var timer:Timer;                     
            private var newRate:int = 0;
            private var mainScreen:Screen = Screen.mainScreen;
            private var newStyle:CSSStyleDeclaration;           
            private var flagPreNext:String="";
            private var flagFullMin:Boolean = false;
            private var monitor:URLMonitor;
            private var timerClosePop:Timer;
            private var sqlStatStatus:SQLStatement;
            private var objSelectedItem:Object;

            [Bindable]
            private var modellocator:DataModel = DataModel.getInstance();

            [Bindable]          
            private var uservo:UserSettingsVo = UserSettingsVo.getInstance();

            private var connection:Connection = Connection.getInstance();

            protected function window1_creationCompleteHandler(event:FlexEvent):void
            {               
                seqEffect.target = this;
                rotate.target = canDesktopVideo;
                loadMovie(0);                           
            }       

            protected function myVidTeaser_completeHandler(event:Event):void
            {
                trace(modellocator.arrMovie[countMovie].Videoname.toString());
                movie = myVidTeaser.content as MovieClip;                           

                if(movie != null)
                {
                    movieTotalFrame = movie.totalFrames;
                    var sizeWidth:Number = 0;
                    var sizeHeight:Number = 0;                      

                    /** Always on top setting **/
                    if(modellocator.userSettingsac[0].alwaysontop == "no")
                    {
                        this.alwaysInFront = false;
                    }
                    else
                    {
                        this.alwaysInFront = true;
                    }                       

                    /** Size Settings **/
                    if(modellocator.flagMaxMin)
                    {
                        sizeWidth = mainScreen.visibleBounds.width;
                        sizeHeight = mainScreen.visibleBounds.height;
                    }
                    else
                    {
                        sizeWidth = mainScreen.visibleBounds.width*(modellocator.userSettingsac[0].size/100);
                        sizeHeight = mainScreen.visibleBounds.height*(modellocator.userSettingsac[0].size/100);
                    }                   

                    if(!this.closed)
                    {
                        this.width = mainScreen.visibleBounds.width;
                        this.height = mainScreen.visibleBounds.height;
                    }

                    modellocator.setSizeWidth = sizeWidth;
                    modellocator.setSizeHeight = sizeHeight;                    
                    rotate.autoCenterTransform = true;
                    rotate.angleYFrom = 0;
                    myMov.xTo = 0;
                    myMov.xFrom = mainScreen.visibleBounds.width;                       
                    myMov.yFrom =  40;
                    myMov.yTo = 40; 
                    myMov.duration = 0;                 
                    fadeEffect.alphaFrom = 0;
                    fadeEffect.alphaTo = 1.0;
                    fadeEffect.duration = 1000;
                    rotate.play();
                    seqEffect.play();
                }                               
            }

            protected function myVidTeaser_enterFrameHandler(event:Event):void
            {
                if(modellocator.flagDesktopVIdeoPlay == true)
                {
                    if(movie != null)
                    {                       
                        if(movie.currentFrame == movieTotalFrame)
                        {                       
                            if(countMovie == (modellocator.arrMovie.length - 1))
                            {
                                countMovie = 0;                     
                            }
                            else
                            {                               
                                countMovie++;
                            }                   

                            /** Show Time Settings **/
                            movie.gotoAndStop(0);
                            System.gc();
                            System.gc();
                            timer = new Timer(int(modellocator.userSettingsac[0].showtime)*60000);
                            timer.addEventListener(TimerEvent.TIMER, movieLoadOnTimer, false, 0, true);
                            timer.start();
                        }
                    }
                }
                else
                {
                    if(timer != null)
                    {
                        timer.stop();
                        timer.removeEventListener(TimerEvent.TIMER, movieLoadOnTimer);
                        timer = null;
                        System.gc();
                        System.gc();
                    }
                    event.preventDefault();
                    event.stopImmediatePropagation();
                }                                   
            }

            private function movieLoadOnTimer(event:TimerEvent):void
            {
                loadMovie(countMovie);
            }

            public function loadMovie(num:int):void
            {
                if(modellocator.arrMovie != null && modellocator.arrMovie.length > 0)
                {
                    if(num < modellocator.arrMovie.length)
                    {
                        if(modellocator.arrMovie[countMovie] != null)
                        {                           
                            if(modellocator.arrMovie[countMovie].VideoBuyFlag == "yes")
                            {   
                                if(flash.system.Capabilities.os.indexOf("Mac") > -1) 
                                {
                                    myVidTeaser.source = "file://" + modellocator.arrMovie[countMovie].VideoFullURL;    
                                }
                                else
                                {
                                    myVidTeaser.source = modellocator.arrMovie[countMovie].VideoFullURL;
                                }
                            }
                            else
                            {   
                                if(flash.system.Capabilities.os.indexOf("Mac") > -1)
                                {
                                    myVidTeaser.source = "file://" + modellocator.arrMovie[countMovie].VideoTeaserURL;
                                }
                                else
                                {
                                    myVidTeaser.source = modellocator.arrMovie[countMovie].VideoTeaserURL;
                                }                   
                            }
                        }                           
                    }
                    else
                    {
                        countMovie = 0;
                        loadMovie(countMovie);
                    }                   
                }
                else
                {
                    this.close();
                }
            }



        ]]>
    </fx:Script>

    <fx:Declarations>
        <s:Move id="moveUp" duration="500" target="{this}" yFrom="350" yTo="0"/>
        <s:Move id="moveDown" duration="500" target="{this}" yFrom="0" yTo="350"/>
        <s:Sequence id="seqEffect">         
            <mx:Move id="myMov"/>           
            <mx:Fade id="fadeEffect"/>
        </s:Sequence>   
        <s:Rotate3D id="rotate"/>
    </fx:Declarations>      

    <mx:Canvas id="canDesktopVideo" width="100%" height="100%" horizontalScrollPolicy="off"
               verticalScrollPolicy="off">
        <s:SWFLoader id="myVidTeaser" right="0" bottom="0" width="{modellocator.setSizeWidth}"
                     height="{modellocator.setSizeHeight}" alpha="{modellocator.setTransparency}"
                     buttonMode="true" 
                     complete="myVidTeaser_completeHandler(event)"
                     enterFrame="myVidTeaser_enterFrameHandler(event)" maintainAspectRatio="true"
                     scaleContent="true"
                     scrollRect="{new Rectangle(0, 0, myVidTeaser.width, myVidTeaser.height)}"
                     useHandCursor="true"/> 
    </mx:Canvas>    
</s:Window>