Ios 设置装入器类的z索引

Ios 设置装入器类的z索引,ios,actionscript-3,flash,air,loader,Ios,Actionscript 3,Flash,Air,Loader,我正在使用Flash AS3,AIR 3.2的iOS SDK。我正在加载一个图像,然后在上面应用一个形状和文本字段。但是z-index似乎与loader类的关系很奇怪。此时,当运行此操作时,将首先应用文本和形状,然后再应用图像,即使这些方法的顺序不同。如何将形状和文本设置为位于从loader类加载的图像上方 主要方法中的方法: displayImage(); overlayBox(); textAnimation(); 方法如下: public function displayImage():

我正在使用Flash AS3,AIR 3.2的iOS SDK。我正在加载一个图像,然后在上面应用一个形状和文本字段。但是z-index似乎与loader类的关系很奇怪。此时,当运行此操作时,将首先应用文本和形状,然后再应用图像,即使这些方法的顺序不同。如何将形状和文本设置为位于从loader类加载的图像上方

主要方法中的方法:

displayImage();
overlayBox();
textAnimation();
方法如下:

public function displayImage():void {

        var imageurl:String = "image.jpg";

        myLoader = new Loader();

        var fileRequest:URLRequest = new URLRequest(imageurl);

        myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
        myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);

        myLoader.load(fileRequest);
    }

public function onLoaderProgress(e:ProgressEvent) {
        trace(e.bytesLoaded, e.bytesTotal); // this is where progress will be monitored
    }

public function onLoaderComplete(e:Event) {

        image = new Bitmap(e.target.content.bitmapData);

        var imageWidth:Number = image.width;
        var imageHeight:Number = image.height;
        var resizeWidthVar:Number;
        var resizeHeightVar:Number;

        trace("Image width: " + image.width);
        trace("Image height: " + image.height);

        if(imageWidth >= imageHeight) {
            resizeHeightVar = imageHeight/displayRes;
            trace("resizeHeightVar = " + resizeHeightVar);

            imageWidth = imageWidth/resizeHeightVar;
            imageHeight = imageHeight/resizeHeightVar;
        }
        else {
            resizeWidthVar = imageWidth/displayRes;
            trace("resizeWidthVar = " + resizeWidthVar);

            imageWidth = imageWidth/resizeWidthVar;
            imageHeight = imageHeight/resizeWidthVar;
         }

        image.width = imageWidth;
        image.height = imageHeight;

        trace("Image width: " + image.width);
        trace("Image height: " + image.height);

        image.x = xScreenPos;
        image.y = yScreenPos;

        addChild(image); // the image is now loaded, so let's add it to the display tree!
    }

public function overlayBox():void {

        var overlaySquare:Sprite = new Sprite();

        addChild(overlaySquare);

        overlaySquare.graphics.beginFill(0x00000, 0.7);
        overlaySquare.graphics.drawRect(0, 0, displayRes, displayRes);
        overlaySquare.graphics.endFill();
        overlaySquare.x = xScreenPos;
        overlaySquare.y = yScreenPos;
    }

public function textAnimation():void {

        //set text format
        textFormat.font = "Helvetica Neue Light";
        textFormat.size = 12;
        textFormat.bold = false;
        textFormat.color = 0x000000;

        // pass text format
        textOne.defaultTextFormat = textFormat;

        textOne.text = "Blah blah blah blah";
        textOne.autoSize = TextFieldAutoSize.LEFT;
        textOne.x = xScreenPos;
        textOne.y = yScreenPos;

        //add to stage
        addChild(textOne);

    }

解决方案之一是替换
addChild(图像)
addChildAt(图像,0)另一个是添加加载程序
addChild(加载程序)并且不要在完整的处理程序中添加图像。

谢谢<代码>addChildAt(图像,0)工作。你能解释一下为什么我必须在显示树中将图像设置为0位置,即使该方法首先运行并首先添加到树中?你可以在完整处理程序中添加图像,当图像加载完成时会异步调用该处理程序,这需要一些时间。是否可以有一个语句告诉它等待
displayImage(),因此处理程序在运行下一个方法之前要完成吗?如果我理解您的意思正确,您希望能够同步加载图像,因为3是单线程的,所以它没有同步加载功能,它将停止所有脚本并查看场景渲染。不,我不希望它同步运行。我想要
displayImage()
先运行,然后
overlybox()
仅在
displayImage()之后运行已完成加载,依此类推。