开发者

as3 how do I load an "image" or "movie" and access its properties like InstanceName and width etc

开发者 https://www.devze.com 2023-03-19 07:35 出处:网络
As2 converting to as3 I would like to: Load a movie or an image Be able to have a loading bar (this is not necessary for now, unless easy)

As2 converting to as3

I would like to:

  1. Load a movie or an image
  2. Be able to have a loading bar (this is not necessary for now, unless easy)
  3. To KNO开发者_StackOverflowW when its loaded
  4. To access its properties like instance name and xPos and yPos so I can tween it on command.

Thanks for your help.

-Ed


This would be different between pure ActionScript or Flex.

Maybe you're looking for something like this Adobe example?

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html

I've pasted the example from Adobe and added to the completeHandler, setting position then accessing a property from the externally loaded SWF.

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.URLRequest;

    public class LoaderExample extends Sprite
    {
        private var url:String = "http://www.jasonsturges.com/js.swf";

        public function LoaderExample()
        {
            var loader:Loader = new Loader();
            configureListeners(loader.contentLoaderInfo);
            loader.addEventListener(MouseEvent.CLICK, clickHandler);

            var request:URLRequest = new URLRequest(url);
            loader.load(request);

            addChild(loader);
        }

        private function configureListeners(dispatcher:IEventDispatcher):void
        {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(Event.INIT, initHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(Event.UNLOAD, unLoadHandler);
        }

        private function completeHandler(event:Event):void
        {
            trace("completeHandler: " + event);

            var loader:Loader = event.target.loader as Loader;
            loader.x = 50;
            loader.y = 50;
            loader.scaleX = (stage.stageWidth - 100) / loader.contentLoaderInfo.width;
            loader.scaleY = (stage.stageHeight - 100) / loader.contentLoaderInfo.height;

            // e-mail text from externally loaded swf:
            trace("var from SWF: " + loader.content["mcContact"]["tfEMail"]["text"]);
        }

        private function httpStatusHandler(event:HTTPStatusEvent):void
        {
            trace("httpStatusHandler: " + event);
        }

        private function initHandler(event:Event):void
        {
            trace("initHandler: " + event);
        }

        private function ioErrorHandler(event:IOErrorEvent):void
        {
            trace("ioErrorHandler: " + event);
        }

        private function openHandler(event:Event):void
        {
            trace("openHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void
        {
            trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }

        private function unLoadHandler(event:Event):void
        {
            trace("unLoadHandler: " + event);
        }

        private function clickHandler(event:MouseEvent):void
        {
            trace("clickHandler: " + event);
            var loader:Loader = Loader(event.target);
            loader.unload();
        }
    }
}

Hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消