0

我正在使用适用于 iOS SDK 的 Flash AS3、AIR 3.2。我正在加载图像,然后在其上应用形状和文本字段。但似乎 z-index 在加载器类中变得很奇怪。目前,当它运行时,首先应用文本和形状,然后将图像应用在这些之上,即使这些方法的顺序不同。如何将形状和文本设置在从加载器类加载的图像上方?

main方法中的方法:

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);

    }
4

1 回答 1

1

一种解决方案是替换addChild(image);addChildAt(image, 0);另一种是添加加载程序addChild(loader);,而不是在完整的处理程序中添加图像。

于 2013-01-31T19:23:11.317 回答