Log in

View Full Version : Full Screen Fade In Issue



tomyknoker
06-15-2007, 12:42 PM
I have some full screen code which works really well... I added a fade in to the code which does work to fade in the image but after 2 minutes the image just dissappears... Thought maybe you AS experts out there might be able to see what I am doing wrong! :) I've commented out the fade in code...


function loadBitmapSmoothed(url:String, target:MovieClip) {
var bmc:MovieClip = target.createEmptyMovieClip("bmc", target.getNextHighestDepth());
var listener:Object = new Object();
listener.tmc = target;
listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
percent = Math.round((bytesLoaded/bytesTotal)*100);
pText.text = percent+"%";
};
listener.onLoadInit = function(mc:MovieClip) {
//fade in image
//mc._alpha=0; // Make mc 'mcl' _alpha 0
//mc.onEnterFrame=function(){ // Create new function
//mc._alpha +=15; // Speed 15

mc._visible = false;
var bitmap:BitmapData = new BitmapData(mc._width, mc._height, true);
this.tmc.attachBitmap(bitmap, this.tmc.getNextHighestDepth(), "auto", true);
bitmap.draw(mc);

// set size and position on load
if (Stage.height/Stage.width>target._height/target._width) {
img_prop = target._width/target._height;
target._height = Stage.height;
target._width = Stage.height*img_prop;
target._y = (Stage.height/2)-(target._height/2);
target._x = (Stage.width/2)-(target._width/2);
} else {
img_prop = target._height/target._width;
target._width = Stage.width;
target._height = Stage.width*img_prop;
target._y = (Stage.height/2)-(target._height/2);
target._x = (Stage.width/2)-(target._width/2);
}//}
};
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmc);
}

Medyman
06-15-2007, 05:24 PM
Why don't you use a tween engine, it'll me a lot better IMO.

Tween Class:

import mx.transitions.Tween;
import mx.transitions.easing.*;

new Tween (mc, "_alpha", Regular.easeOut, 0, 100, 1, true);


MC Tween:

#include "mc_tween2.as"

mc._alpha = 0
mc.alphaTo(100, 1, "easeOutQuad")


btw, still can't get your other file to open :(

tomyknoker
06-19-2007, 03:21 AM
Hi Medyman... Really? Maybe it's corrupt I'll take a look... So tween engine you think, where abouts would I add that to my code?

Medyman
06-20-2007, 10:50 PM
You would add that to the same place where you're existing fade function is.

didlo
07-06-2007, 06:08 AM
Hi,
I agree with the other people about you using one of the tweening classes to do this, however it may be useful for you to know why your original code was producing the results that it did.

There is no condition in your onEnterFrame to stop it ie

if(mc._alpha >= 100)delete this.onEnterFrame;

so the onEnterFrame keeps executing - this is probably as you are using it to resize the image when the stage resizes.

The result is that mc._alpha keeps getting incremented by 15 on each frame - when it reaches 12800 it will change to -12800 and then start adding 15 to that. This is one of those things in flash that you don't look out for unless you know that it is there - why would you want to set the alpha of an mc to more than 100.

You should be using a tween for the fade in as others have stated.
You should try to make sure that wherever possible you NEVER leave an onEnterFrame running.
You should have a function to resize the mc when it first loads eg resizeMc() . Then handle any changes in Stage size by adding a listener to the Stage object and calling your resizeMc() function with the onResize event. There is an example in the help files.

Hope this helps.