A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: 1 Sprite, 2 DisplayObjectContainers?

  1. #1
    Member
    Join Date
    Mar 2004
    Posts
    45

    1 Sprite, 2 DisplayObjectContainers?

    I'm not sure if this is possible, but I'd like to somehow put 1 Sprite into 2 displayObjectContainers. Here is an example:

    Code:
    var image:Sprite = new Image();
    
    var containerA:Sprite = new Sprite();
    containerA.x = stage.stageWidth / 2;
    containerA.y = stage.stageHeight / 2;
    addChild(containerA);
    
    var containerB:Sprite = new Sprite();
    containerB.x = stage.stageWidth/1.5;
    containerB.y = stage.stageHeight/1.5;
    addChild(containerB);
    
    containerA.addChild(image);
    containerB.addChild(image);
    What i'd like is for the image instance to display twice, in both containers.
    If I changed image.x, it'd change in both containerA, and containerB.

    In this example, it only displays once (in containerB).

    Is what I want possible? If so, how?

    Cheers,

    David

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    No, it's not possible to display the same DisplayObject as a direct child of two different containers. Putting it in the second removes it from the first.

    You'll have to either create a second instance of the Image, or a Bitmap and draw the image in the bitmap. Either way, you will also need to write some code to synchronize changes if you want them to be reflected in the second copy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center