Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 632011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:01:45+00:00 2026-05-13T20:01:45+00:00

I have a class (ImageLoader) that extends Sprite container and loads an external image

  • 0

I have a class (ImageLoader) that extends Sprite container and loads an external image to its instance. When i instantiate an object of this class from another (Main) class i want to have the dimensions (width, height) of the loaded image being known to this (Main) class. It seems that is difficult for me as the dimensions are known after the image compete loaded. But i don’t know how to pass this information from completeHandler event handler to the Main class. Any ideas?


package
{
import flash.display.Sprite;
import flash.events.Event;

public class Main extends Sprite
{       
    private const img1:String = "pic1.jpg";
    private const img2:String = "pic2.jpg";

    private var myImg1:ImageLoader;
    private var myImg2:ImageLoader;

    public function Main():void
    {                                   
        myImg1 = new ImageLoader( img1 );
        myImg1.cacheAsBitmap = true;        

        myImg1.addEventListener(ImageLoader.COMPLETE, onImageLoadComplete);     

        addChild( myImg1 );         
    }               

    private function onImageLoadComplete(evt : Event) : void 
    {
        trace (ImageLoader(evt.currentTarget).getWidth());
        trace (ImageLoader(evt.currentTarget).getHeight());
    }

}

}


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

public class ImageLoader extends Sprite
{
    private var loader:Loader;
    private var iWidth:int;
    private var iHeight:int;        

    public static const COMPLETE : String = "complete";

    public function ImageLoader( name:String ):void
    {               
        loader = new Loader();          
        loader.contentLoaderInfo.addEventListener( Event.COMPLETE, completeHandler );

        var request:URLRequest = new URLRequest( name );

        loader.load( request );
    }

    public function getWidth():int
    {
        return iWidth;
    }

    public function getHeight():int
    {
        return iHeight;
    }

    private function completeHandler( event:Event ):void
    {   
                    iWidth = event.target.content.width
        iHeight = event.target.content.height;

                    /* dispatcher MUST be after dimension computations */       
        dispatchEvent(new Event(ImageLoader.COMPLETE));

        this.addChild( loader.content );
    }       
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:01:46+00:00Added an answer on May 13, 2026 at 8:01 pm

    You can get the width and height of the image using the ImageLoader object public functions getWidth and getHeight but you need to know when the load is complete, so you could dispatch a event from ImageLoader completeHandler, like:

    // declare public static constant
    public static const COMPLETE : String = "complete";
    // inside complete handler
    dispatchEvent(new Event(ImageLoader.COMPLETE));
    

    done with this you can now listen to this event from your Main class like this:

    myImg2 = new ImageLoader( img2 );
    myImg2.addEventListener(ImageLoader.COMPLETE, onImageLoadComplete);
    
    // inside onImageLoadComplete handler you can read the width and height:
    private function loadComplete(evt : Event) : void 
    {
        trace (ImageLoader(evt.currentTarget).getWidth());
        trace (ImageLoader(evt.currentTarget).getHeight());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 342k
  • Answers 342k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ActionFixture does not work with Slim. It is used with… May 14, 2026 at 5:14 am
  • Editorial Team
    Editorial Team added an answer For these types of "write-only queries" I usually use a… May 14, 2026 at 5:14 am
  • Editorial Team
    Editorial Team added an answer Use the SQL 2005 upgrade advisor to spot any problems… May 14, 2026 at 5:14 am

Related Questions

in AS3, I have an external class ImageLoader, that loads an image upon request.
As we all know, when we derive a class and use polymorphism, someone, somewhere
An application I have reads in quite large images (jpegs) but only needs to
I believe the factory method design pattern is appropriate for what I'm trying to
I need a little guidance here... I have 2 links: <div class=tarjBodyHolder> <div class=imageHolder>

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.