• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

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
0
winniewsp
Asked:
winniewsp
  • 2
  • 2
1 Solution
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now