How do I position a Loader image inside a Sprite?

In AS3 / CS4 I'm trying to programmatically create a bunch of rectangular objects, let's call them 'cards', that will contain an image and a colored background and eventually some other elements like text.  I want to create alot of these cards and move them around inside of a larger panel (also a Sprite) of sorts.  I can successfully create colored rectangles in my cards and place the cards where I want in the panel, but whenever I try to add an image to a card, I can't seem to position the image inside the card's coordinate space, it ends up being placed inside the larger panel's coordinate space instead, even though I'm adding the image/loader as a child of the card.  I thought maybe it had something to do with having to wait until the image loading was complete, so I added the listener as a test but that didn't work.  Here's the code:
            var cont:Sprite = new Sprite();  containing 'card'
            var rect:Sprite = new Sprite();  // draw a colored rectangle in the card
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, positionLoader);
            rect.graphics.beginFill(0xbb3399);
            rect.graphics.drawRect(60,60,99,99);  // this works as expected
            rect.graphics.endFill();
            cont.addChild(rect);
            addChild(cont);
            var req:URLRequest = new URLRequest("top.png");
            loader.load(req);
            function positionLoader(e:Event):void {
                loader.x = 30;  // position the image inside the containing card
                loader.y = 30;
                cont.addChild(loader);  // add the image to the card

I solved this problem.

Similar Messages

  • How do I create a duplicate image inside the same page? Then how do I change the color of that image

    how do I create a duplicate image inside the same page? Then how do I change the color of that image from black to red?

    Hello there!
    Here is one way to create a duplicate image and colorize it. As you can see below, I have one image right now, that I want to duplicate.
    My layers panel looks like below.
    To duplicate your image, click the downward arrow on the right side of your Layer Panel.
    Select Duplicate Layer. This will duplicate the layer that the image is on.
    Select "OK" to approve the duplication.
    As you can now see in the Layers panel, the image is duplicated. The new layer is now at the top of the Layer panel.
    Now to colorize your image, go to Window > Adjustments.
    The Adjustments panel will now be opened. Select the Hue and Saturation icon as seen circled in red.
    The Hue and Saturation propertied panel will be opened. I selected "Colorize", and adjusted the hue and saturation bar to achieve the level red in my photo.
    As you can see below, the image is now red.
    Now i want to make sure only ONE of my image layers is red. I moved the Hue and Saturation layer to only be on top of the bottom layer. The image on the top layer now will not be affected by the red.
    Select the move tool, so I can now move the image layers so we can see both of them.
    With each image layer selected, you can take the move tool and move the images. I moved mine on top of eachother and you can see my red layer (bottom) and the non red layer (top).
    I hope that helps. i have also included helpful links.
    Please post back with any questions,
    Janelle

  • How to replace wecenter default loading image(ss.gif).

    Hi All ,
    I am working on webcenter customization .
    Can anyone provide me how to replace webcenter default loading image which appears before webcenter content gets loaded .
    Appreciate any prompt response .
    Thanks ,
    Arun.

    If it's the splash screen you speak of, a custom skin defining these selectors may work - af|document::splash-screen, af|document::splash-screen-content, af|document::splash-screen-message and af|document::splash-screen-icon.
    Please note that I have not tried these myself.

  • Loading images inside applet JAR

    Hi
    This is my issue: I have an applet which contains images inside the applet JAR. I want to display these images in my applet, but apparently due to browser access restrictions, I'm not allowed.
    My first code was like this:
    //security restrictions on browsers do not allow getResource
    ImageIO.read(MyClass.class.getResource("imgs/img.png"));
    //getResourceAsStream should be allowed by browsers
    ImageIO.read(MyClass.class.getResourceAsStream("imgs/img.png"));Both lines work when I execute the applet locally (command line / programming IDE), but when I deploy it to my web server, the resource "imgs/img.png" becomes a relative URL to my web application context (like /webcontext/MyClass/imgs/img.png). It works locally because the call to getResource returns a URL object with "file:" protocol, but I need it to look for my images bundled inside the JAR, not web hosted images.
    I need to avoid making the applet look for these images as a web resource... how can I do it?
    Thanks!

    dev@java wrote:
    warnerja wrote:
    I'm not convinced the code you posted wouldn't work, but since this is an applet, you have access to the Applet class. Check out the Applet.getImage method in conjunction with Applet.getCodeBase.
    [http://java.sun.com/javase/6/docs/api/java/applet/Applet.html]
    getCodeBase returns my web context, like http://myhost.com/mycontext/ , so it is pretty much the same as above.
    Thanks for your replyThat is the way to load resources though. Hence back to my earlier statement about not being convinced it would not work, with this addition: It should work, assuming you actually do have the resources properly located with the web app, whether they be in a jar, or loose files relative to where the web app is. My guess at this point is that they are not.

  • Loading images inside the package structure

    i am having trouble loading images that are imbedded into the package structure. I am assuming this is possible(99.9% sure)
    the classes are
    cardgameframework/CardGame.class
    cardgameframework/cardsupport/Card.class
    cardgameframework/cardsupport/images/2D.GIF
    cardgameframework/cardsupport/images/2C.GIF
    how do i load 2D.gif and 2C.gif from CardGame
    i tried
    Image i = Toolkit.getDefaultToolkit.getImage(
    "/cardgameframe/cardsupport/images/2C.GIF");
    and
    Image i = Toolkit.getDefaultToolkit.getImage(getClass().getResource(
    "/cardgameframe/cardsupport/images/2C.GIF"));
    but neither of these seem 2 work
    any help would be appreciated

    My initial thought is that you've got the package wrong in your two examples - you've got cardgameframe and not cardgameframework.
    Anyway, I tend to use the latter of your approaches - getClass().getResource("/cardgameframework/cardsupport/images/2D.GIF").
    Be careful of case in your URLs.
    Note that if getResource can't find your file it will return null - ensure that you're getting back a non-null URL:
    URL url = getClass().getResource("/cardgameframework/cardsupport/images/2D.GIF");
    System.out.println("URL: " + url);
    ...If your URL is non-null then the problem will be with the format of your image file (if it is null then you'll get a NullPointerException eventually).
    Hope this helps.

  • How do I make a loader image similar to those shown at program opening?

    I'm looking to build a loader image, that opens up at the start of my script, and automatically closes after a few seconds. I opened up the image processor script to see how Adobe has added images to alerts, but it's an extensive doc, and I couldn't tell where the image was being pulled from, as the variable only shows up twice, and is only called, and not set. Also is there another method other than alert to call a box like this? I would prefer it have no buttons.

    I was able to boil your script down, to what I need. Works great in extendscript, but for some reason, only shows a portion of the image in photoshop and illustrator. This was happening even before i boiled it down. Thoughts? The last thing I'm trying to do with it, is figure out if I can set a transparent background for the window. I also tried using backgroundColor, but was unable to set the attribute correctly... there is a lot to learn with Adobe scripting. I also couldn't find reference to what DELTA_H is, I have a bunch of their PDFs, and googled, but couldn't find reference to this. I'm trying to be resourceful so I don't have to ask such remedial questions.
    Here's the revised script, and a link to the image I labelled test on my desktop: http://img2.wikia.nocookie.net/__cb20110725041802/logopedia/images/8/89/Logo_rolling_stone s.png
    PreviewWindow = function() {
    w = 285;
    h = 313;
    PreviewWindow.DELTA_H = 1;
    PreviewWindow.open = function(file, w, h, title, ms) {
      PreviewWindow.openFile(file, w, h, title, ms);
    PreviewWindow.openFile = function(file, w, h, title, ms) {
      var type = (ms > 0) ? 'palette' : 'dialog';
      var win = new Window(type, title || "Preview: " + decodeURI(file.name),undefined,{borderless : true});
      win.preview = win.add('image', undefined);
      win.preview.icon = file;
      win.show();
      if (ms > 0) {
        $.sleep(ms);
      delete win;
      $.gc();
      PreviewWindow.open("~/Desktop/test.png", undefined, undefined,
                         "Preview Test", 500);

  • How to check width of loaded image

    Hi my script loads an image like this:
            image = new Sprite();
            imageLoader = new Loader;
            imageLoader.load(new URLRequest(imageList.image[1].imgURL));
            image.addChildAt(imageLoader, 0);
    how can i check the width of loaded image? trace(image.width) gives 0...

    You need to wait until the image is loaded before you can try to ffind its width.  To do that you need to use the contentLoaderInfo property of the Loader class
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, manageImage);
    The manageImage event handler function is where you can check things since it is triggered after the object is loaded.

  • How do you size dynamically loaded images?

    Hi,
    I am loading images from mysql into flash using php, I need
    to make thumbnails out of these images, so they need to be resized
    as they are loaded in and then displayed to one set size. Does
    anyone have any ideas?
    thanks
    Gavin

    Jan-Paul K>
    i thought it was _xscale & _yscale?
    thahip>
    if what you need is "one set size", then use _width &
    _height.

  • How search for a string or image inside an image?

    Here's what I want to do:
    1. The user has an image that they don't know if they or someone else applied some modification to (either drawing some text on it or an image)
    2. The program can look and see if he text is drawn at a specific size, font, style, location, angle and alpha on the image (or an image done much the same way on top)
    How would I do this? Is it possible to look for that pattern without the original, unmarked image? (So you couldn't compare it and see if the pixels in that location differ the right way)
    Is this even possible in Java? Where do i start?

    >
    The second way (with no original image to compare to) might be impossible.>No, no. That is what the scrying is for, just scan (or grab an image via a webcam) the crystal ball for an image to work with, then proceed with the strategy you outlined for comparing 2 images. ;-)
    As far as image filters that compare one image with another, you might first look to a video processing tool such as AviSynth. It is a script based video editing tool (that can work equally well with static images), that provides a whole heap of image operations that allow easy comparison of images. I mention it because I am guessing you will see an image operation that works for your purposes, and can then research the filter type for how to go about implementing it in Java.
    For (vague) example, one image subtracts the other, with a 'minimum threshold' set to account for the slight changes that might occur between PNG and JPEG - if there are no changes, the resulting image should be 'black'.

  • Loading Images/Having images load at the center of a JFrame with random col

    Hey Guys,
    I was wondering how could i go about loading images two at a time for instance have two circle images load at the center of a J Frame connected to each other and also each time the J Frame is executed the circles are different colors. Ive posted this question before and have posted it on another forum but i have not gotten any help. I looked into using media tracker and the Random command but i am still not if these are the proper solution to my problem. Id appreciate any help if this post doesn't make sense let me know i will try and clarify better. Thanks in advance

    Ah alright then so what i have to far is i have an image load to my J Frame/J Panel and after it loads it starts to fall like a tetris block and i am able to move it left and right. When the image loads it loads to the default coordinates of 0,0 the left hand top corner. What i want to do it when i run my application the image loads at the center of the J Frame/J Panel but also have another block connected to it when it loads. So basically i have loaded four separate different images and want them to load to my J Frame/ J Panel two at a time side by side like tetris and puyo puyo smashed together here is my code sorry its hard for me to explain it for some reason hope this makes more sense.
    import javax.swing.*;
    import java.awt.*;
    public class DemoTest extends JPanel {
         public DemoTest() {
            add(new BlockPanel());
        public static void main(String[] args) { {
        JFrame frame = new JFrame("Tetris");
        frame.setContentPane(new BlockPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200,500);
        frame.setResizable(false);
        frame.setVisible(true);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class BlockAnimation extends JPanel {
      public static final int numDroppingBlocks=2;
      private static final int MAX_X = 200;
      private static final int MAX_Y = 430;
      private static final int DELTA_Y = 2;
      private static final int TIMER_DELAY = 20;
       // Declare name's for the Image object.
       Image image[];
       Timer pptimer;
       boolean right,left;
       int X = 0;
       int x = 32;
       int y;
    public BlockAnimation() {
          super();
          //Load an image file into the Image object. This file has to be in the same folder
          image = new Image[4];
          image[0] = Toolkit.getDefaultToolkit().getImage("block_yellow.png");
          image[1] = Toolkit.getDefaultToolkit().getImage("block_blue.png");
          image[2] = Toolkit.getDefaultToolkit().getImage("block_green.png");
          image[3] = Toolkit.getDefaultToolkit().getImage("block_red.png");
        //image5 = Toolkit.getDefaultToolkit().getImage("DeathNote1.jpg");
          setFocusable(true);
          BlockMove block_move = new BlockMove(); // Make a new video game KeyListener
          addKeyListener(block_move);
          //setBackground(Color.BLACK);
          pptimer = new Timer(TIMER_DELAY, new TimerAction());
          pptimer.start();
            public void setAnimation(boolean OnandOff) {
            if (OnandOff) {
                pptimer.start(); 
            } else {
                pptimer.stop(); 
            public void paintComponent(Graphics g) {
             super.paintComponent(g); 
             // draw the "stop" line for the animation
             g.setColor(Color.black);
             g.drawLine(0, MAX_Y, getWidth(), MAX_Y);
                // Draw our Image object.
           g.drawImage(image[0],X,y,this);
             if(right) // Move the block to the right
                   X++;
                   if(left) // Move the block to the left
                  X--;
                 repaint();
         private class BlockMove implements KeyListener {
         public void keyTyped(KeyEvent e){}
          public void keyReleased(KeyEvent e)
           if(e.getKeyCode() == e.VK_RIGHT)
            right = false;
            if(e.getKeyCode() == e.VK_LEFT)
              left = false;
                   public void  keyPressed(KeyEvent e)
                  if(e.getKeyCode() == e.VK_RIGHT)
                             right = true;
                        if(e.getKeyCode() == e.VK_LEFT)
                             left = true;
            class TimerAction implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                 y += DELTA_Y;
                if (y + x  >= MAX_Y) {
                setAnimation(false);
    }//end class
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class BlockPanel extends JPanel {
       BlockAnimation pa;  
        BlockPanel() {
            pa = new BlockAnimation();       
            JButton startButton = new JButton("Start");       
            JButton stopButton  = new JButton("Stop");
            startButton.addActionListener(new Start());
            stopButton.addActionListener(new Stop());
            JPanel button = new JPanel();
            button.setLayout(new FlowLayout());
            button.add(startButton);
            button.add(stopButton);
            this.setLayout(new BorderLayout());
            this.add(button, BorderLayout.SOUTH);
            this.add(pa,BorderLayout.CENTER);
        class Start implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                pa.setAnimation(true);
        class Stop implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                pa.setAnimation(false);
    }//endclass Edited by: Riz01 on Sep 14, 2009 2:34 PM

  • How do you position an image inside a photo box?

    I'm trying to create a 20 page 16x8 book and I cannot figure out how, after putting a photo box on the page, and dropping an image into it, how do I move the image around inside of it. For instance if I create a square photo box, how do I position a 3:2 image inside of it?

    Double click it.
    RB

  • How to center loaded image?

    First time building an app for AIR, from Flash CS4, as I needed to be able to write to a local XML file... all is working except I cannot manage to center a loaded image properly. I am running it full screen and everything I try width / height wise gives me my desktop resolution - which I guess is right since it's full screen. However positioning goes from the stage's top/left corner - not the monitor's top/left corner.
    This image illustrates the issue - when I query the size I get the red rectangle size... but when I position something it uses the green rect - ie the actual stage. How do I fix in AIR?

    is you stage align property set to StageAlign.TOP_LEFT ?

  • How can i postition an image inside a div correctly?

    I am learning CSS and I want to insert an image inside a div
    used as a footer. I want the image to appear to the left of the div
    with say 10px left margin and 5px top and bottom.
    I also have a horizontal UL and a <p> inside the div
    which are set to the centre. I want to keep their appearance as
    they are - but add the image to the left without putting anything
    else out of place if that makes sense.
    Can someone show me how it is done?
    http://www.tomkilbourn.com/newsite/test/footer.html
    The image which I want to use is from validator.wc3.org -
    <p>
    <a href="
    http://validator.w3.org/check?uri=referer"><img
    src="
    http://www.w3.org/Icons/valid-xhtml10"
    alt="Valid XHTML 1.0 Transitional" height="31" width="88"
    /></a>
    </p>

    ~Billy~ wrote:
    > Ive got it to work by adding -
    >
    > <span
    style="position:absolute;top:27px;left:20px;">
    > <img src="/newsite/images/valid-xhtml10.png"
    /></span>
    >
    > before the closing body tag, but is there a way to do it
    without using
    > absolute positioning and span?
    >
    Id' do it by adding position relative to my footer div and
    then I'd
    create a class for the img and use absolute positioning for
    it which if
    nested within the footer div will be relative to that - like
    so.....
    in your css...
    #footer {
    border-top: 1px solid rgb(187, 187, 187);
    padding: 0px 0px 10px;
    background-color: rgb(51, 0, 0);
    position: relative;
    .w3c {
    position: absolute;
    top: 10px;
    right: 20px;
    and your html markup for your footer dive, something like....
    <div id="footer">
    <img src="/newsite/images/valid-xhtml10.png" alt="alt text
    here"
    class="w3c" />
    <ul id="navlist">
    <li><a href="#">Item one</a></li>
    <li><a href="#">Item two</a></li>
    <li><a href="#">Item three</a></li>
    <li><a href="#">Item four</a></li>
    <li class="last"><a href="#">Item
    five</a></li>
    </ul>
    <p id="footerbottom">Copyright Tom Kilbourn 2007
    www.tomkilbourn.com</p>
    </div>
    chin chin
    Sinclair

  • How do i backup the list of load images automatically exceptions under Options- Content. I want to transfer to another comp without re-adding one at a time

    How do i backup the list of load images automatically exceptions under Options->Content. I want to transfer to another comp without re-adding one at a time. EVen if there is no way to backup, what is the system file for Firefox that stores these, so i can transfer this file or open it in an XML or similar editor to copy them out?

    The permissions.sqlite file stores 'allow' and 'block' exceptions for cookies, images, pop-up windows, and extensions (software) installation.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    You can use this button to go to the Firefox profile folder:
    *Help > Troubleshooting Information > Profile Directory: Show Folder
    See also:
    *https://support.mozilla.org/kb/Recovering+important+data+from+an+old+profile
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • How do i get a placed image to appear as image inside a layer?

    There is a long winded reason why I want this, but in essence I am trying to replicate another artwork that has been supplied to me.
    When I place a Photoshop image (TIFF / PSD etc) how can I get it so that it simply appears as <image> inside the relevant layer (screen shot attached)
    I am finding that when I place an image I do not get this

    That's what I had assumed. It just doesn't seem to be working for me. You don't think there is a Preference setting that might disable it?

Maybe you are looking for

  • Adding multiple e-mail alias addresses to an account

    Can someone please tell me how to add another e-mail address to my Mail account. I have tried using info from the Mail Help file, both "adding another account" and "adding multiple e-mail alias addresses to an account". Each time when I try to send a

  • MacBook pro and uncompressed editing????

    I'm about to buy a 2nd edit system (currently running dual G5, AJA IO, with FCP 5 and, 3TB of SATA uncompressed storage) I need this next system to be mobile but still do uncompressed video. I see that you can use the AJA IO with the old MacBooks but

  • Best practice for getting all Activities for a Contact

    Hello, I am new to the Eloqua API and am wondering what is the best practice for downloading a list of all activities for a given contact. Thanks

  • Unable to read PDF files

    I have a new Mac Mini which I just migrated from an old iMac (the one with the half-dome base). Some PDF files came over with it and some have been received since. When I click on them I get the following message: You can't open the application becau

  • GW8.0.3hp1 OES2 to OES11 migration

    Leading up to migrating our GW8 to GW2012 I need to move our GW8 system to a GW2012 supported OS as the old one is running on SLES10.2 with OES2sp1. (I've been putting this off far too long, its too easy to delay something when there is no urgency ;)