On Tue, Feb 9, 2010 at 8:24 AM, Greg Ligierko <[email protected]> wrote:

> All display objects have registration points (their internal 0,0
> coordinates). Also bitmaps.
>
> By default a loaded image (png) has its registration point in the
> top-left corner. If you like to get rid of the improperly set
> registration point then you may place the loaded image into a parent
> container and align the image centrally inside its parent:
>
>  stage -> parent_container -> your_image
>
> You can do this by creating a new Sprite (or MovieClip) in the
> Event.COMPLETE handler:
>
>  function loaded(evt:Event):void
>  {
>            //create the parent
>           var parent_container:Sprite = new Sprite();
>           // ...and add it to the stage
>           addChild(parent_container)
>
>           var loaderInfo:LoaderInfo = evt.target as LoaderInfo;
>           var displayObject:DisplayObject = loaderInfo.content;
>           displayObject.width = 150;
>           displayObject.height = 150;
>
>            // instead, move the parent
>           //displayObject.x = 1000;
>           //displayObject.y = 208;
>           parent_container.x = 1000;
>           parent_container.y = 208;
>
>           //note that the displayObject is added to parent_container
>           parent_container.addChild(displayObject);
>
>           // now, place the displayObject's center over its parent
>           // (0,0) point, by moving half width and half height in
>           // top-left direction
>           displayObject.x = -displayObject.width / 2;
>           displayObject.y = -displayObject.height / 2;
>
>           // see what you get:
>           trace('parent_container.x: ' + parent_container.x);
>           trace('parent_container.y: ' + parent_container.y);
>           trace('displayObject.x: ' + displayObject.x);
>           trace('displayObject.y: ' + displayObject.y);
>
>           //..
>
>           //.. continue with tween etc. but (!) perform all operations on
>           // the parent container:
>           parent_container.alpha = 0;
>           TweenLite.to(parent_container, 1, {x:65, y:117, scaleX:0.5,
>            scaleY:0.5, rotation:520, alpha:1});
>  }
>
>
Well now that makes a lot of sense! However, here's what's traced:

parent_container.x: 100
parent_container.y: 208
displayObject.x: -75
displayObject.y: -75

and the object doesn't show up. I've been playing with values for the x and
y of displayObject but with no satisfactory results. Just to be on the safe
side, the code follows. Please advise once again.
TIA,
beno

package
{
import flash.display.Sprite;
import flash.events.Event;
   import flash.events.ProgressEvent;
   import flash.events.Event;
   import flash.events.MouseEvent;
   import flash.display.MovieClip;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.DisplayObject;
import flash.net.URLRequest;
import flash.display.Shape;
import flash.geom.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.GlowFilter;
import flash.filters.BitmapFilterQuality;
import flash.geom.Rectangle;
import com.greensock.*;
   import com.greensock.easing.*;
import SpinningWorld;
 public class GlobalSolutions extends MovieClip
   {
      //Import Library Assests
public var mySpinningWorld:SpinningWorld;
public var radius:int = 500;
public var textureMap:BitmapData;
public var myLogo:Bitmap;
          var parent_container:Sprite = new Sprite();
      public function GlobalSolutions()
      {
         init();
      }

      public function init():void
      {
mySpinningWorld = new SpinningWorld();
mySpinningWorld.x = -500;
mySpinningWorld.y = -500;
mySpinningWorld.alpha = 0;
addChild(mySpinningWorld);
TweenLite.to(mySpinningWorld, 1, {x:-100, y:0, scaleX:0.4, scaleY:0.4,
alpha:1});
loadImage();
}

private function loadImage():void
{
          addChild(parent_container)

var path:String = "images/logo.png";
var req:URLRequest = new URLRequest(path);
var loader:Loader = new Loader();
loader.load(req);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
}

function loaded(evt:Event):void
{
var loaderInfo:LoaderInfo = evt.target as LoaderInfo;
var displayObject:DisplayObject = loaderInfo.content;
displayObject.width = 150;
displayObject.height = 150;
          parent_container.x = 100;
          parent_container.y = 208;
          parent_container.addChild(displayObject);
          displayObject.x = -displayObject.width / 2;
          displayObject.y = -displayObject.height / 2;
          trace('parent_container.x: ' + parent_container.x);
          trace('parent_container.y: ' + parent_container.y);
          trace('displayObject.x: ' + displayObject.x);
          trace('displayObject.y: ' + displayObject.y);

addChild(displayObject);
displayObject.alpha = 0;
TweenLite.to(parent_container, 1, {x:65, y:117, scaleX:0.5, scaleY:0.5,
rotation:520, alpha:1});
}
// DisplayList
   }
}
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to