从XML,闪光,ActionScript 3.0中的图像加载到单独的影片剪辑闪光、图像、影片剪辑、加载

2023-09-09 21:46:07 作者:vitamin(维他命)

我有一个XML图片库,pretty的标准,我有一个加载器,以及我想要加载到图像影片剪辑,我正在运行到是我想要的图像加载到单独的问题影片剪辑,所以我使用一个case语句来指定他们去。但是,我只能让他们加载到单个影片剪辑,我以为他们正在装载ontop对方,我不知道如何让他们分开了。我会后我的code。它没有任何意义,我,但如果你有这将是真正伟大的任何建议。

我可以做独立的装载机,然后就做1图像每装载机,但只是不健全的权利给我。

  VAR counterNumber:数= 0;

   功能callThumbs():无效{
     对于(VAR我:数量= 0;我3;;我++){
        thumbLoaded();
        counterNumber ++;
     }
   }




    传播thumbLoaded(){

    VAR photoLoader =新的Loader();

    开关(counterNumber){

            情况1:
                photoLoader.load(新的URLRequest(影片剪辑(this.parent).xml.photos.imageOne.image @网址[0]));
                whole.boxOne.pictureLoader.addChild(photoLoader);
                跟踪(1Done);
                打破;

            案例2:
                photoLoader.load(新的URLRequest(影片剪辑(this.parent).xml.photos.imageTwo.image @网址[0]));
                whole.boxTwo.pictureLoader.addChild(photoLoader);
                跟踪(2Done);
                打破;
       }
   }
 

解决方案

下面是我会去做。我唯一​​没有做的是改变影片剪辑的位置都装有影像后他们。你可以在imageLoaded()函数,这个功能很容易地添加。

将下面的code的AS3 FL​​A文件的第一帧的动作面板上。这假定存在于同一目录中的FLA / SWF一个名为图像目录。

  //创建一个图像文件名的数组
VAR文件名:阵列=新的Array();
文件名[0] ='some_image.jpg';
文件名[1] ='some_other_image.jpg';
文件名[2] ='and_another.jpg';

//声明变量
常量IMAGES_DIRECTORY:字符串=图像/';
VAR装载机:阵列=新的Array();
VAR影片剪辑:阵列=新的Array();

//这个函数实例化装载机对象所需的具体数量
//并启动加载过程为每个图像文件。因为每个图象被加载,
// imageLoaded()被调用
功能createLoaders(filenamesAsArray:阵列,目录:字符串):无效
{
    对于(VAR我:= 0; I< filenamesAsArray.length;我++)
    {
        装载机[我] =新的Loader();
        装载机[I] .load(新的URLRequest(目录+ filenamesAsArray [I]));
        装载机[I] .contentLoaderInfo.addEventListener(引发Event.COMPLETE,imageLoaded);
    }
}

createLoaders(文件名,IMAGES_DIRECTORY);

//这个函数被调用,因为每个Loader对象是完全加载
//它创建每个影片剪辑,添加图像,然后添加MC到舞台
功能imageLoaded(五:事件):无效
{
    如果(e.target.content.bitmapData)
    {
        变种MC:影片剪辑=新的MovieClip();
        VAR BMP:位图=新位图(e.target.content.bitmapData);
        mc.addChild(BMP);
        movieClips.push(MC);
        的addChild(影片剪辑[movieClips.length  -  1]);
    }
}
 
actionscript3.0中如何给按钮添加代码来控制视频的播放,暂停和停止 添加什么代码 具体如何添加

关于导入XML数据

窥视 XML对象。

加载XML实例

XML文档的例子:

 <图片>
    <图像>
        <冠军>一个女人的肖像​​&LT的; /标题>
        <文件名> portrait.jpg< /文件名>
    < /图片>
    <图像>
        <冠军>乡村景观和LT; /标题>
        <文件名> landscape.jpg< /文件名>
    < /图片>
    <图像>
        <标题>我的猫< /标题>
        <文件名> cat.jpg< /文件名>
    < /图片>
< /图片>
 

在AS3装载上述XML文档

  //实例化一些对象(URLoader和XML)
VAR xmlLoader:的URLLoader =新的URLLoader();
VAR XMLDATA:XML =新的XML();

//收听的URLLoader(xmlLoader)的实例来触发引发Event.COMPLETE,
//这将调用命名的函数的loadXML()
xmlLoader.addEventListener(引发Event.COMPLETE,loadXML的);

//启动加载XML文件的过程
//在这种情况下,的test.xml位于同一目录中的SWF / FLA
//这个code位于
xmlLoader.load(新的URLRequest('的test.xml'));

//这是将通过事件监听上述被调用的函数(时
//该xmlLoader信号引发Event.COMPLETE
功能的loadXML(五:事件):无效
{
    //检索XML文档的内容
    XMLDATA =新的XML(e.target.data);

    //跟踪整个文档:
    跟踪(XMLDATA);

    //跟踪的文件名的第一个<图像>节点
    跟踪(xmlData.image [0] .filename);
}
 

当然,XML文档可能有很大差别,在这种情况下,你需要在实践中获取所需的确切信息。这是最棘手的部分,在我看来。此外,你会想实例化一个数组的 loadXML的函数中的范围之内。然后,递归填充从XML文档文件名的数组。

I have an xml image bank, pretty standard, and I have a loader, along with movie clips that I want the images loaded into, the problem that I am running into is I want the images to load into separate movie clips, so I’m using a case statement to specify where they go. However, I can only get them to load into a single movie clip, I assume they are loading ontop of each other and I don’t know how to get them to separate out. I’ll post my code. It doesn’t make any sense to me but if you have any suggestions that would be real great.

I can make separate loaders and then just do 1 image per loader, but that just doesn’t sound right to me.

   var counterNumber:Number = 0;

   function callThumbs():void{
     for (var i:Number = 0; i <3; i++){
        thumbLoaded();
        counterNumber++;
     }
   }




    function thumbLoaded(){

    var photoLoader = new Loader();

    switch (counterNumber){

            case 1:
                photoLoader.load(new URLRequest(MovieClip(this.parent).xml.photos.imageOne.image.@url[0]));
                whole.boxOne.pictureLoader.addChild(photoLoader);
                trace("1Done");
                break;

            case 2:
                photoLoader.load(new URLRequest(MovieClip(this.parent).xml.photos.imageTwo.image.@url[0]));
                whole.boxTwo.pictureLoader.addChild(photoLoader);
                trace("2Done");
                break;    
       }
   }

解决方案

Here is how I would go about it. The only thing I did not do is change the position of the MovieClips after they are loaded with the images. You could easily add in this feature in the imageLoaded() function.

Put the following code on the Actions panel of the first frame of an AS3 FLA file. This assumes that a directory named 'images' exists in the same directory as the FLA/SWF.

//Create array of image filenames
var filenames:Array = new Array();
filenames[0] = 'some_image.jpg';
filenames[1] = 'some_other_image.jpg';
filenames[2] = 'and_another.jpg';

//Declare variables
const IMAGES_DIRECTORY:String = 'images/';
var loaders:Array = new Array();
var movieClips:Array = new Array();

//This function instantiates the exact number of Loader objects that are required
//and initiates the loading process for each image file. As each image is loaded,
//imageLoaded() is called
function createLoaders(filenamesAsArray:Array, directory:String):void
{
    for(var i:int = 0; i < filenamesAsArray.length; i++)
    {
        loaders[i] = new Loader();
        loaders[i].load(new URLRequest(directory + filenamesAsArray[i]));
        loaders[i].contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
    }
}

createLoaders(filenames, IMAGES_DIRECTORY);

//This function is called as each Loader object is completely loaded
//It creates each individual movieclip, adds the image to it, and then adds the MC to the stage
function imageLoaded(e:Event):void
{
    if(e.target.content.bitmapData)
    {
        var mc:MovieClip = new MovieClip();
        var bmp:Bitmap = new Bitmap(e.target.content.bitmapData);
        mc.addChild(bmp);
        movieClips.push(mc);
        addChild(movieClips[movieClips.length - 1]);
    }
}

About importing XML data

Look into the XML Object.

Loading XML Example

The XML Document for the Example:

<images>
    <image>
        <title>Portrait of a Woman</title>
        <filename>portrait.jpg</filename>
    </image>
    <image>
        <title>Rural Landscape</title>
        <filename>landscape.jpg</filename>
    </image>
    <image>
        <title>My Cat</title>
        <filename>cat.jpg</filename>
    </image>
</images>

The AS3 for Loading the above XML Document

//Instantiate some objects (URLoader and XML)
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

//Listen for the instance of URLLoader (xmlLoader) to trigger Event.COMPLETE,
//which will call the function named 'loadXML()'
xmlLoader.addEventListener(Event.COMPLETE, loadXML);

//Initiate the process of loading the XML document
//In this case, 'test.xml' is located in the same directory as the SWF/FLA
//that this code is located in
xmlLoader.load(new URLRequest('test.xml'));

//This is the function that will be called by the event listener above (when
//the xmlLoader signals Event.COMPLETE
function loadXML(e:Event):void
{
    //Retrieve the contents of the XML document
    xmlData = new XML(e.target.data);

    //Trace the entire document:
    trace(xmlData);

    //Trace the filename for the first <image> node
    trace(xmlData.image[0].filename);
}

Of course, your XML document may be very different, in which case, you need to practice retrieving the exact information that you want. This is the trickiest part, in my opinion. Also, you would want to instantiate an array outside of the scope of the loadXML function above. Then, recursively fill the array with the filenames from the XML document.