闪存中的XML库在本地工作,但不在服务器上工作

时间:2014-09-13 00:44:17

标签: xml actionscript-3 flash

Link In Google drive to project

从服务器访问时,图库显示正在加载图片1/2并挂起。

在网站上,整个文件夹内容已上传到服务器。

它也会抛出错误:

  

SecurityError:错误#2000:没有安全上下文处于活动状态。

[谷歌驱动器上的网站] [1]

package {

import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.xml.*;
import caurina.transitions.*;

public class Gallery extends MovieClip 
{ 
    var urlLoader:URLLoader = new URLLoader();         
    var xml:XML; 
    var list:XMLList; 
    var picsList:XMLList;

    var themeButtons:Array = new Array();
    var themeClicked:MovieClip = new ThemeButton();

    var i:int;
    var j:int;

    var smallPicSource:Array;
    var bigPicSource:Array;
    var smallPics:Array;
    var picTitles:Array;

    var bigLoader:Loader;

    var bigPic:String;
    var bigClicked:String;

    var cpi:uint;

    var ratio:Number

    public function Gallery():void
    { 
        urlLoader.load(new URLRequest("pics.xml")); 
        urlLoader.addEventListener(Event.COMPLETE, urlLoadComplete); 

        stage.addEventListener(MouseEvent.MOUSE_MOVE, slideTheme); 
    } 

    protected function urlLoadComplete(e:Event):void{
        xml = new XML(urlLoader.data);
        list = new XMLList(xml.children()); 
        for(i = 0; i<list.length(); i++){       
            var themeButton:MovieClip = new ThemeButton();
            themeButton.txt.text = list[i].@name;
            themeButton.name = list[i].@name;

            themeButton.addEventListener(MouseEvent.CLICK, themeClick);

            themeButton.x = i*(themeButton.width+10);
            themes.addChild(themeButton);

            themeButtons[i] = themeButton;
        }
        themes.x = 720-themes.width/2;
    }

    protected function themeClick(e:MouseEvent):void{
        if (themeClicked != e.currentTarget){
            smallPicsMc.visible = false;
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, slideSmallPics);   
            j = 0;

            if(img.numChildren > 0)
                img.removeChildAt(0);
            txtField.text = "";

            if (themeClicked != null){
                themeClicked.alpha = 0.5;
                themeClicked.addEventListener(MouseEvent.ROLL_OUT, themeClicked.rollOut);
            }
            themeClicked = MovieClip(e.currentTarget);
            themeClicked.alpha = 1;
            themeClicked.removeEventListener(MouseEvent.ROLL_OUT, themeClicked.rollOut);
            for (i=0; i<themeButtons.length; i++)
            {
                if (e.currentTarget.name == themeButtons[i].name)
                {
                    picsList = new XMLList(list[i].pic);    
                }
            }
            if (smallPicsMc.numChildren != 0){
                for(i=smallPicsMc.numChildren; i>0; i--)
                    smallPicsMc.removeChildAt(i-1);
            }

            if (picsList.length() > 0)
            {
                smallPicSource = new Array();
                bigPicSource = new Array();
                smallPics = new Array();
                picTitles = new Array();

                for(i=0; i<picsList.length(); i++){
                    smallPicSource[i] = "pics/small/" +  e.currentTarget.name +"/" + picsList.@filename[i];
                    bigPicSource[i] = "pics/big/" +  e.currentTarget.name +"/" + picsList.@filename[i];
                    picTitles[i] = picsList.@title[i];
                }

                j = -1;
                smallPicLoad(null);
            }else
            {
                if(img.numChildren > 0)
                    img.removeChildAt(0);
                txtField.text = "Coming soon...";
            }
        }
    }

    protected function smallPicLoad(e:Event):void
    {
        if (j < smallPicSource.length-1)
        {
            j++;
            txtField.text = "Loading thumbs: " + (j+1).toString() +" / " + (smallPicSource.length).toString();
            smallPics[j] = new Loader();
            smallPics[j].load(new URLRequest(smallPicSource[j]));
            smallPics[j].contentLoaderInfo.addEventListener(Event.COMPLETE, smallPicLoad);
        }else
        {
            smallPicComplete();
        }
    }

    protected function smallPicComplete(e: Event = null):void{
        bigClicked = bigPicSource[0];
        loadPic(bigPicSource[0]);
        cpi = 0;

        var smallPicButtons:Array = new Array();

        for(i=0; i<smallPics.length; i++){
            smallPicButtons[i] = new SmallPicButton();
            smallPicButtons[i].addChild(smallPics[i]);

            if (i>0)
                smallPicButtons[i].x = smallPicButtons[i-1].x+smallPicButtons[i-1].width+20;
            smallPicButtons[i].data = bigPicSource[i];

            smallPicsMc.addChild(smallPicButtons[i]);
            smallPicButtons[i].addEventListener(MouseEvent.CLICK, click);
        }

        smallPicsMc.visible = true;
        smallPicsMc.alpha = 0;
        Tweener.addTween(smallPicsMc, {alpha:1, time:1});
        stage.addEventListener(MouseEvent.MOUSE_MOVE, slideSmallPics);

        nextArrow.addEventListener(MouseEvent.CLICK, nextPic);
        prevArrow.addEventListener(MouseEvent.CLICK, prevPic);
        prevArrow.visible = false;
        nextArrow.visible = true;
        prevArrow.buttonMode = true;
        nextArrow.buttonMode = true;
    }

    protected function nextPic(e:Event = null):void
    {
        if (cpi < bigPicSource.length-1)
        {
            cpi++;
            loadPic(bigPicSource[cpi]);
        }
    }

    protected function prevPic(e:Event = null):void
    {
        if (cpi > 0)
        {
            cpi--;
            loadPic(bigPicSource[cpi]);
        }
    }

    protected function loadPic(bigPic):void
    {   
        if(img.numChildren > 0)
            img.removeChildAt(0);
        txtField.text = "";

        bigLoader = new Loader();
        bigLoader.load(new URLRequest(bigPic));
        bigLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
        bigLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, bigLoadComplete);
        for (i=0; i<bigPicSource.length; i++)
        {
            if (bigPic == bigPicSource[i])
            {
                cpi = i;
            }
        }

        if (cpi > 0)
            prevArrow.visible = true;
        if (cpi == 0)
            prevArrow.visible = false;

        if (cpi == bigPicSource.length-1)
            nextArrow.visible = false;
        if (cpi < bigPicSource.length-1)
            nextArrow.visible = true;
    }

    protected function progress(e: ProgressEvent): void {
        txtField.text = "Loading picture: " + Math.floor((e.bytesLoaded / e.bytesTotal) * 100) + "%";
    }

    protected function bigLoadComplete(e:Event):void{
        txtField.text = "";
        txtField.text = picTitles[cpi];

        var bitmap:Bitmap = e.target.content;
        bitmap.smoothing = true;
        var origWidth:Number = bitmap.width;
        var origHeight:Number = bitmap.height;

        var maxWidth = 840;
        var maxHeight = 420;

        var newWidth:Number;
        var newHeight:Number;

        var ratio:Number = origWidth / origHeight;

        if (origWidth > maxWidth || origHeight > maxHeight)
        {
            if (maxWidth - origWidth > maxHeight - origHeight)
            {
                newHeight = maxHeight;
                newWidth = Math.round(newHeight * ratio);
            }else
            {
                newWidth = maxWidth;
                newHeight = Math.round(newWidth / ratio);
            }
        }else
        {
            newHeight = origHeight;
            newWidth = origWidth;
        }

        bitmap.width = newWidth;
        bitmap.height = newHeight;
        bitmap.x = -bitmap.width/2;
        bitmap.y = -bitmap.height/2;

        img.addChild(bitmap);

        img.alpha = 0;
        Tweener.addTween(img, {alpha:1, time:1});
    }
    protected function click(e:MouseEvent):void
    {       
        if (bigClicked != e.currentTarget.data){
            if(img.numChildren > 0)
                img.removeChildAt(0);
            txtField.text = "";
            bigClicked = e.currentTarget.data;
            bigPic = e.currentTarget.data;
            loadPic(bigPic);
        }
    }

    protected function slideSmallPics(e:MouseEvent):void
    {
        if(mouseY>870 && mouseY<1150){
            ratio = smallPicsMc.width/850;
            if(smallPicsMc.width > 900)
            {
                Tweener.addTween(smallPicsMc, {x: (450-smallPicsMc.width/2)-(mouseX-450)*ratio, time: 1});
            }
            else
            {
                Tweener.addTween(smallPicsMc, {x: (450-smallPicsMc.width/2), time: 1});
            }
        }
    }

    protected function slideTheme(e:MouseEvent):void
    {
        if(mouseY>850 && mouseY<870){
            ratio = themes.width/900;
            if(themes.width > 1440)
            {
                Tweener.addTween(themes, {x: (720-themes.width/2)-(mouseX-450)*ratio, time: 1});
            }
            else
            {
                Tweener.addTween(themes, {x: (720-themes.width/2), time: 1});
            }
        }
    }
}
}

0 个答案:

没有答案