Cannot addChilld(sprite) into another sprite?

Hi,

First post woo,

Anyways, I’m quite new to AS3, I worked a bit with AS2 but not to a great extent, and I am now trying to teach myself AS3 (with a little help). I am creating a flash portfolio and so far have got images to import via XML and some other things, but I am stuck at one particular point:

I have an AS file called Statics.as that extends Sprite, it will contain all the code to draw the static elements of the portfolio, so far it draws a rounded rectange with gradient fine.

I then used URLRequest() and URLLoader() to load the XML, and then Loader to load the logo of the portfolio. I can add it to the Sprite now with:

addChild(logoLoader);

But I want to manipulate the x and y coords first. I initially failed as I tried to position it in the top right of the portfolio using:

logoLoader.x = 720-logoLoader.width -10

(720 being the width of the portfolio, and 10 being the padding from the right)

This did not work, after tracing logoLoader.width it seems that this property is not given and so tells me the width of the logo is 0. Therefore the x coord of the logo was mostly off the screen.

I then tried putting the logo into its own sprite to manipulate using:

var logoSprite:Sprite = new Sprite;
logoSprite.addChild(logoLoader);
logoSprite.addEventListener(Event.ADDED,logoComplete);

This didn’t throw any errors, so I continued with:

public function logoComplete(evnt:Event)
{
     evnt.target.x = 720-evnt.target.width -10;
     trace(evnt.target.x);
}

This gave me an x coord value of 382 which is correct, this would position the logo in the top right hand corner in exactly the place I wanted.

But when I tried adding it as a child to the class, I got an error:

1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display: DisplayObject.

I believe the problem is that I am trying to add a Sprite as a child into a Sprite. As AS3 is quite new to me, I don’t see why this should be a problem or a way around it, so my question is; Is what I am doing, the right way of manipulating the position of an external image before it being added to the stage?

Thankyou for your time,

Any reply is appreciated,

Blekk.

P.S.

A new instance of the AS file Statics.as is added to the stage via the DocumentClass.

Here is all the code relevant to the problem if needed:

package com.fusedDesign.userinterface
{
    import flash.display.*;
    import flash.geom.*;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.events.*;
    
    public class Statics extends MovieClip
    {
        public function Statics()
        {
            drawModule();
            drawLogo();
        }
        
        public function drawLogo()
        {
            var urlRequest:URLRequest = new URLRequest("com/fusedDesign/folio/xml.xml");
            var urlLoader:URLLoader = new URLLoader();
            urlLoader.load(urlRequest);
            urlLoader.addEventListener(Event.COMPLETE,xmlComplete);
        }
        
        public function xmlComplete(evnt:Event)
        {
            var imagesXML:XML = new XML(evnt.target.data);
            loadImage(imagesXML);
        }
        
        public function loadImage(xml:XML)
        {                    
                 var logoLoader:Loader = new Loader();
                var logoRequest:URLRequest = new URLRequest(xml.logo.attribute("href")[0]);
                logoLoader.load(logoRequest);
                var logo:Sprite = new Sprite();
                logo.addChild(logoLoader);
                logo.addEventListener(Event.ADDED,logoLoaded);
         }
        
        public function logoLoaded(evnt:Event)
        {
            trace("added");
            evnt.target.x = 720-evnt.target.width-10;
            evnt.target.y = 10;
            addChild(evnt.target);
        }
    }
}

I have removed the code that draws and adds the rounded rectangle.