Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

image loader fade

New Here ,
Feb 26, 2013 Feb 26, 2013

Hi

I am loading eternal images into a moviclip:

          function loadImage(url:String):void {

                    imageLoader = new Loader();

                    imageLoader.load(new URLRequest(url));

                    imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);

                    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);

          }

          loadImage("images/" + image + ".jpg");

          function imageLoading(e:ProgressEvent) {

                    loading_mc.play();

                    var percent:int=e.bytesLoaded/e.bytesTotal*100;

                    loaderStatus.text="LOADING";

          }

          function imageLoaded(e:Event):void {

                    if (image_mc.loadedImage) {

  image_mc.removeChild( image_mc.loadedImage );

                    }

image_mc.loadedImage=imageLoader;

                    image_mc.addChild(imageLoader);

                    loading_mc.gotoAndPlay(1);

                    loaderStatus.text=" ";

          }

I'm having trouble fading in each image. Can anyone help?

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Feb 26, 2013 Feb 26, 2013

function imageLoaded(e:Event):void {

          if (image_mc.loadedImage) {

                    image_mc.removeChild( image_mc.loadedImage );

          }

 

          image_mc.loadedImage=imageLoader;

          image_mc.addChild(imageLoader);

          loading_mc.gotoAndPlay(1);

          loaderStatus.text=" ";

 

          // Fade in

          image_mc.alpha = 0;

          image_mc.addEventListener(Event.ENTER_FRAME, fadeIn);

}

function fadeIn(e:Event):void

{

          var fadeTarget:DispayObject = e.target as

...
Translate
Engaged ,
Feb 26, 2013 Feb 26, 2013

Add an ENTER_FRAME listener and modify the alpha of your image_mc from 0 to 1 depending on the rate you want it to fade in after it loads.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2013 Feb 26, 2013

can you give me an example please? Everytime I've tried to add a fade to the movieclip, it fades in just the once and not everytime an image is loaded.

Many thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 26, 2013 Feb 26, 2013

function imageLoaded(e:Event):void {

          if (image_mc.loadedImage) {

                    image_mc.removeChild( image_mc.loadedImage );

          }

 

          image_mc.loadedImage=imageLoader;

          image_mc.addChild(imageLoader);

          loading_mc.gotoAndPlay(1);

          loaderStatus.text=" ";

 

          // Fade in

          image_mc.alpha = 0;

          image_mc.addEventListener(Event.ENTER_FRAME, fadeIn);

}

function fadeIn(e:Event):void

{

          var fadeTarget:DispayObject = e.target as DisplayObject;

 

          fadeTarget.alpha += 0.05;

 

          if (fadeTarget.alpha >= 1)

          {

                    fadeTarget.alpha = 1;

                    fadeTarget.removeEventListener(Event.ENTER_FRAME, fadeIn);

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2013 Feb 26, 2013

Thanks so much for the code.

I am getting an error with this line

var fadeTarget:DispayObject=e.target as DisplayObject;

1046: Type was not found or was not a compile-time constant: DispayObject..

How can I solve this?

Thanks again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 26, 2013 Feb 26, 2013

If you ever get a type error that means you are not importing the class. An easy way to do this with Flash Builder is to place your cursor at the end of the type and press Control + Space and then choose the right one if it gives you multiple options.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 27, 2013 Feb 27, 2013

Many thanks for your help!!!!

I have another question - relating to this so I haven't posted another question. Hope you don't mind helping again!?

What is the best way to unload the imageloader?

I don't want to get rid of it.

If the image loader loads a specific image, I want to clear another movieclip, but not remove it.

I end up removing it, so when I need to load the movieclip with the image again - it can't find it!

Hope that makes sense?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 27, 2013 Feb 27, 2013

Just save it in a dictionary for later retrieval by a key you can predict:

var imageLoaders:Dictionary = new Dictionary();

function loadImage(url:String):void {

          imageLoader = new Loader();

          imageLoader.load(new URLRequest(url));

          imageLoader.contentLoaderInfo.addEventListener(ProgressEven t.PROGRESS, imageLoading);

          imageLoader.contentLoaderInfo.addEventListener(Event.COMPLE TE, imageLoaded);

 

          // Save for later use

          imageLoaders[url] = imageLoader;

}

and then you would just check imageLoaders[url] and if that isn't null that is where your Loader will be.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 28, 2013 Feb 28, 2013

Thank you Nabren!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 28, 2013 Feb 28, 2013
LATEST

Hi again Nabren, I've come across another issue and was wondering if you could shed some light?

The movieclip that fades in, is resized on the next frame.

After adding the fadein fuction, the image shows up as the normal size.

I want to resize and postiton the movieclip but it doesn't happen with the fadein function.

Why is this?

Thanks for your help again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines