Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5996599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:07:33+00:00 2026-05-23T00:07:33+00:00

I am building a Custom Image Picker, that shows 6 alternative versions. However the

  • 0

I am building a Custom Image Picker, that shows 6 alternative versions. However the photo is only showing on the 6th item.

_model.selectedPhoto returns a Sprite, and does not let the app function correctly.

However when I use _model.photos[ii], A photo is added to each item – Why is this? I need to add _model.selectedPhoto to each s: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);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:07:34+00:00Added an answer on May 23, 2026 at 12:07 am

    Ummm it’s only showing the one photo on the 6th item because you’re running a for loop 6 times and adding the selected photo to each new sprite in succession. You see when you add a display object to another display object, and then add that same display object to something else, the original item is pulled from the first display object and added to the next. I know that might be hard to understand when written that way so lets break to down this way:

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

    That is why when you use _model.photos[ii] you add a unique picture to each of the 6 new container sprites you’re making in your for loop, because there are unique items to add to each container. You’re accessing these unique items by using an array index (the ii var) which increments with each loop.

    If you want to add the same picture to each six items, then you’re going to need to duplicate the data of the original picture 6 times. One way you can do this is by using a URLLoader object and reloading the binary data that makes up the original picture. You’d do this like so:

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

    Now keep in mind this is just one method AND I’ve written this off the top of my head. So, I’m not sure but you MAY need to duplicate the pictureBytes data inside the for loop but I don’t believe so. If you did have to, this is how you’d do it:

    var bytesCopy:ByteArray = new ByteArray();
    pictureBytes.position = 0;
    bytesCopy.writeBytes(pictureBytes);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a custom view inside of Interface Builder that has buttons with image
I am building a custom control that looks like the one in the image
I am building a custom image upload form in Rails 3 (paperclip / carrierwave
I'm building a custom RTE that converts user input to a homebrewn markup, now
I'm building a web app where users can build custom web pages that pull
I am building a text-to-image generator that takes a text, a font, a max
I'm building a codeigniter application that will serve custom microsites. Essentially each microsite will
I am building an application that makes heavy use of Enum s for custom
I'm building a Windows Mobile Compact Frameworks custom control that has optional images as
I'm building an Android program that includes a custom list view. The list itself

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.