...

View Full Version : AS3 Load an image into a MovieClip



tomharto
02-22-2012, 10:32 PM
I have a movieclip 'MainImage', what i need to load an image into, also the image needs to be centered in it too.

Can anyone give me a hand sorting this out?

waxdoc
02-22-2012, 11:56 PM
loadMovie() into a MovieClip and loadMovieNum() were used in AS2 [I have to check my syntax here]

Let me also check my notes on AS3 Loader class methodology.

So the basic question is: Are you using AS2 or AS3?

tomharto
02-23-2012, 12:06 AM
Im using actionscript 3.

I've just found this


//URL of the external image content
var myRequest:URLRequest=new URLRequest("images/3.jpg");

//Create a new Loader to load the image
var loader:Loader = new Loader()

//Load the external image into the Loader
loader.load(myRequest)

// Listen when the loading of image is completed
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadTheImage);



function loadTheImage(evt:Event):void {
//Display the Loader on the MainTimeline
//The holder_mc (new symbol) was created before by:
/*
Insert -> New Symbol -> Select MovieClip
Give this new symbol any name you like (e.g. MyImage)
Return to the scene.
Drag the MovieClip (e.g. MyImage) into your scene from the Library window
Give the instance name of this MovieClip "holder_mc"
*/
MainImage.addChild(loader)


/*
You can add fun to the picture showing up, e.g. TransitionManager
Note:
Remember to add Classes to use the Transition Effect at the beginning
import fl.transitions.*;
import fl.transitions.easing.*;

Please see "Transition Effect + Tween Animation (2)"

TransitionManager.start(holder_mc, {
type: PixelDissolve,
direction: Transition.IN,
duration: 3,
easing: None.easeNone,
xSections: 20,
ySections: 20
}
);
*/

}

That loads the image into my movieclip however its not centered,but im not sure why, will i have to mess with the margins to get it centered?

waxdoc
02-23-2012, 01:02 AM
For AS2 see http://www.verticalmoon.com/tutorials/swfnslide/loadmovie/loadmovie.htm


... add the loadMovie command to the maintimeline.The first parameter is the name of the .swf file you want to load and display. The second parameter is the instance name where you want the movie to be loaded in to.
loadMovie("slideshow.swf", holderMC);


For AS3, see http://www.iheartactionscript.com/loading-an-external-swf-in-as3/
http://www.republicofcode.com/tutorials/flash/as3loader/
http://www.flashandmath.com/intermediate/swfload/
http://www.flashandmath.com/howtos/externalswf/
http://kb2.adobe.com/cps/141/tn_14190.html ]covers both AS3 LOADER class and AS2 loadMovie() method]



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum