Adding multiple sprite instances?

I am creating a Custom Image Picker that shows 6 alternative versions. However, a photograph is displayed only on the 6th element.

_model.selectedPhoto Sprite returns and does not allow the application function correctly.

However, when I use _model.photos[ii], a photo is added to each element. Why is this? I need to add _model.selectedPhototo eachs:Sprite

        for (var ii:int; ii < 6; ii++)
        {
            //Create BG
            var s:Sprite = new Sprite();
            s.graphics.beginFill(Math.random() * 0xffffff, 0.4);
            s.graphics.drawRect(0, 0, 291, 184);
            //add Photo
            var p:Sprite = new Sprite();
            p.addChild(_model.selectedPhoto);
            p.scaleX = p.scaleY = 0.2;
            p.x = 0;
            p.y = 0;
            s.addChild(p);
            cards.push(s);
        }
0
source share
2 answers

Ummm, 6- , 6 . , , - , . , , , :

var photo:Sprite = new Sprite();

var container1:Sprite = new Sprite();

var container2:Sprite = new Sprite();

//Add to the first container
container1.addChild(photo);

//At this point when you add to the next container, the object is removed from container1 and placed inside container 2
container2.addChild(photo);

, _model.photos [ii], 6 , for, . , (ii var), .

, 6 . - URLLoader , . :

var originalPictureLoader:URLLoader = new URLLoader();

originalPictureLoader.addEventListener(Event.COMPLETE, originalPictureLoaded);

originalPictureLoader.dataFormat = URLLoaderDataFormat.BINARY;

originalPicture.load(new URLRequest("http://www.mysite.com/picture.jpg"));

private function originalPictureLoaded(e:Event):void
{
    var pictureBytes:ByteArray = URLLoader(e.currentTarget).data as ByteArray;

    var imageDiplicateLoader:Loader;

    for (var ii:int; ii < 6; ii++)
    {
        //Create BG
        var s:Sprite = new Sprite();
        s.graphics.beginFill(Math.random() * 0xffffff, 0.4);
        s.graphics.drawRect(0, 0, 291, 184);
        //add Photo
        var p:Sprite = new Sprite();

        imageDiplicateLoader = new Loader();
        imageDiplicateLoader.loadBytes(pictureBytes);

        p.addChild(imageDiplicateLoader);
        p.scaleX = p.scaleY = 0.2;
        p.x = 0;
        p.y = 0;
        s.addChild(p);
        cards.push(s);
    }
}

, , . , , pictureBytes for, . , :

var bytesCopy:ByteArray = new ByteArray();
pictureBytes.position = 0;
bytesCopy.writeBytes(pictureBytes);
+3

, , ; DisplayObject ( Sprite) , , , . , .

+2
source

All Articles