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

  • SEARCH
  • Home
  • 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 6714415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:29:36+00:00 2026-05-26T08:29:36+00:00

I was wondering if it is possible to implement any logic to wiat for

  • 0

I was wondering if it is possible to implement any logic to wiat for the image to complete load without freezing.

For the sake of my app, I created a class which takes image url in constructor and loads the mx.controls.Image using the “load()” function.

See the class below

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

import mx.controls.Alert;
import mx.controls.Image;
//import mx.utils.OnDemandEventDispatcher;

public class SpriteImage extends Sprite
{
    //Pass the source path or url here.
    private var imageUrl:String;
    private var ready:int = -1;
    private var img:Image;

    public function SpriteImage(imgUrl:String)
    {
        //imageUrl = imgUrl;
        loadImage(imgUrl);
    }
    private function loadImage(imgUrl:String):void
    {

        img = new Image();
        img.addEventListener(Event.COMPLETE,onCompleteHandler);
        img.addEventListener(IOErrorEvent.IO_ERROR,onErrorHandler);     
        //img.source = imgUrl;
        img.load(imgUrl);

    }

    private function onCompleteHandler(e:Event):void{

        img.x = -(img.width/2);
        img.y = -(img.height/2);
        this.addChild(img);
        ready = 1;
    }

    private function onErrorHandler(e:IOErrorEvent):void
    {
        ready = 0;
        //Alert.show("Can't load :" + e.toString());
    }

    public function prepare():Boolean{

        while(ready == -1){
            trace(0);
        }           
        return ready;
    }
}

}

Now, I use this class from main app like this

var img:SpriteImage = new SpriteImage(e.imageUrl);
img.prepare(); // just waits till image is loaded but freezes
var obj:DisplayObject = img;

Now the problem is that the app never comes out of the prepare() method. It freezes the browser and I have to kill the plugin process to unfreez the app.

The main criteria here is that I need to wait for the image to complete loading so that I can access the image in the next steps. How can I do this.? Please help

  • 1 1 Answer
  • 3 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-26T08:29:37+00:00Added an answer on May 26, 2026 at 8:29 am

    Looks to me like you’re creating the freeze yourself with that while(ready == -1) Why don’t you just disable the ability for a user to go further in your “steps” until the image is loaded?

    You don’t have to synchronously wait for the image to load the way you do now. Once the image is loaded, you’ll get the notification by the complete event that its loader dispatches. Then you can enable whatever depends on that image being loaded.

    One straight forward way is to bind the enabled property of the navigation controls in your application to a boolean property. For example in your SpriteImage add

    [Bindable] public var isImageLoaded:Boolean = false;
    

    and set it to true once the onCompleteHandler is called. You can bind to that property’s value. Another way is to dispatch an event from your class to notify others that the image is loaded and that something can happen :]

    Blaze

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was wondering if there by any chance is possible to implement an exposed
I'm wondering how you'd implement the following use-case in REST. Is it even possible
I'm wondering if its possible to add new class data members at run-time in
I was wondering if its possible to inject a thread into a remote app
Is it possible to implement friend function and friend class (as in c++) in
In my asp.net mvc 2 app, I'm wondering about the best way to implement
I'm new to Scala but I was wondering it it is possible to implement
Hey guys, I was wondering if it were possible to translate audio without having
I was wondering if it is possible to implement a web based game in
In C++, is it possible to have a base plus derived class implement a

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.