Flash Actionscript, How to show a series of different sized images

In ActionScript 3.0 I want to show a series of images with a transition between them. I don’t need any user interaction, just to show a new image every so many seconds.

I am using the TransitionManager to do this – please see the attached code and images.

The problem I have is that the second image is smaller than the first and after the transition occurs I can still see part of the first image.

Does anyone know how to correct this?

Thanks,
Winnie

import fl.transitions.easing.*;
import fl.transitions.*;

var photoCounter:int=0;
var photoTimer:Timer=new Timer(2000,7);
photoTimer.start();

function showPhoto(evt:TimerEvent):void {
	photoCounter +=1;
	var photoLoader:Loader=new Loader();
	photoLoader.load(new URLRequest("photo"+photoCounter+".jpg"));
	photoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
}

photoTimer.addEventListener(TimerEvent.TIMER, showPhoto);

function loadComplete(evt:Event):void {
	var image:Bitmap=Bitmap(evt.target.content);
	var pictureFrame:MovieClip = new MovieClip();
	pictureFrame.x=0;
	pictureFrame.y=0;
	addChild(pictureFrame);
	pictureFrame.addChild(image);
	
	TransitionManager.start(pictureFrame, {type:Wipe, direction:Transition.IN, duration:2, easing:None.easeNone, startPoint:1});
}

Open in new window

photo1.jpg
photo2.jpg
winniewspAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AreDubyaCommented:
winniewsp,

If you declare the pictureFrame outside of the function, it will be one container that will be refilled. By declaring it inside the function, every time the timer fires you are creating another container and placing it over the old one. Hope that helped.

AreDubya
import fl.transitions.easing.*;
import fl.transitions.*;

var photoCounter:int=0;
var photoTimer:Timer=new Timer(2000,7);
var pictureFrame:MovieClip = new MovieClip();

photoTimer.start();

function showPhoto(evt:TimerEvent):void {
	photoCounter +=1;
	var photoLoader:Loader=new Loader();
	photoLoader.load(new URLRequest("photo"+photoCounter+".jpg"));
	photoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
}

photoTimer.addEventListener(TimerEvent.TIMER, showPhoto);

function loadComplete(evt:Event):void {
	var image:Bitmap=Bitmap(evt.target.content);
	pictureFrame.x=0;
	pictureFrame.y=0;
	addChild(pictureFrame);
	pictureFrame.addChild(image);
	
	TransitionManager.start(pictureFrame, {type:Wipe, direction:Transition.IN, duration:2, easing:None.easeNone, startPoint:1});
}

Open in new window

0
winniewspAuthor Commented:
Hiya

Thanks for that, I tried your suggestion but the problem was still there. However, I have fixed the problem by copying the Bitmap to a new one of a fixed size before adding it to the Movieclip thus:

function loadComplete(evt:Event):void {
             ...
         addChild(pictureFrame);

        // get a pointer to the bitmaps data
      var imgData:BitmapData = image.bitmapData;
      
      // create a new fixed height data canvas
      var canvasData:BitmapData = new BitmapData(300, 300, false, 0x00000000);
      
      // copy the image to the new canvas
      var imgRect:Rectangle = new Rectangle(0,0,imgData.width,imgData.height);
      canvasData.copyPixels(imgData, imgRect, new Point(0,0));
      
      // draw a rectangle on the remaining part of the new canvas
      
      // create a new image from the data
      var newImage:Bitmap = new Bitmap(canvasData);

      pictureFrame.addChild(newImage);

Many thanks
Winnie
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AreDubyaCommented:
Winnie,

Sorry - should have thought of that. Sometimes the fingers move faster than the brain....

AreDubya
0
winniewspAuthor Commented:
thats ok - will study your ideas anyway :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.