Question

I've loaded a AS2 swf into a AS3 swf but the onLoadInit function for a MovieClipLoader object isn't executing; which leaves my images not centered and not reduced in dimensions (width/height)

It works if i run the AS2 swf (gallery) directly.

    listenerObj.onLoadInit = function (target:MovieClip) {
        if (target._height > _root.maxHeight) 
        {
            var ratio = target._height / _root.maxHeight;
            target._height = target._height/ratio;
            target._width = target._width/ratio;
        }
        if (target_mc._width > _root.maxWidth) 
        {
            var ratio = target._width / _root.maxWidth;
            target._height = target._height/ratio;
            target._width = target._width/ratio;
        }
        target._x = ((Stage.width/2)-(target._width/2));
        target._y = ((Stage.height/2)-(target._height/2));
    }
    MCL.addListener(listenerObj);
Was it helpful?

Solution

There are unfortunately some subtle differences in behavior and bugs when loading an AS2 movie in AS3. I also experience the behavior you're seeing--none of the load handlers work on the listener when the movie is loaded in AS3. There are some strange issues when loading AVM1 movies, particularly when nesting loads.

Perhaps the best you can do is to look onEnterFrame to poll for when the clips are loaded. One way is to watch for _width != 0. This should happen once the clip has loaded. Then you can initialize the position:

function onEnterFrame()
{
  if(target._width)
  {
    // your positioning+init code here
    onEnterFrame = null;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top