Flash As3 help Imageloader
- Started
- Last post
- 12 Responses
- OBBTKN
I´ve been searching for something specific and can´t get on it... I´ve got a movie where the user clicking on buttons define the image is goin to be shown on a specific target mc. But i need this image to be external to the library of the flash file.
I´ve got this script for the image loader:
var myImageLoader:Loader = new Loader();
var myImageLocation:URLRequest = new URLRequest("IMG/opcion.png");
myImageLoader.load(myImageLocati...
addChild(myImageLoader);and this for the navigation into the images:
stop();
btn1.addEventListener(MouseEvent...
function play1(event:MouseEvent):void{
mc.gotoAndStop ("op1")
}
btn2.addEventListener(MouseEvent...
function play2(event:MouseEvent):void{
mc.gotoAndStop ("op2")
}
btn3.addEventListener(MouseEvent...
function play3(event:MouseEvent):void{
mc.gotoAndStop ("op3")
}
btn4.addEventListener(MouseEvent...
function play4(event:MouseEvent):void{
mc.gotoAndStop ("op4")
}But, i need something to mix it. A code that on mouseclick loads a especific .png on a container mc.
Can anyone help me on this?
Thanks a lot!
* And yes, i´m new in AS3, it´s not my usual playground;)
- woodygoestohollywood0
I believe you need to put this "myImageLoader.load(myImageLocat...
addChild(myImageLoader);"inside of the button handler
- PonyBoy0
if you're only loading 4 images - load all 4 at the same time and just set the movieclip holding each image to:
myImage. visible = false;
myImage. alpha = 0;when you click each button - call a function that changes the alpha / visibility for each image so only the image you want is showing
button1. addEventListener (MouseEvent.MOUSE_DOWN, button1Function);
function button1Function () {
image1. alpha =1;
image1. visible = true;
image2. alpha =0;
image2. visible = false;
image3. alpha =0;
image3. visible = false;
image4. alpha =0;
image4. visible = false;
}this is redundant when you do it for four buttons - ideally you'd like to run one function and pass a parameter to that function telling the function what button you pressed in turn running a switch statement or a 'for' loop to adjust the mc alpha / visibility - but as you're new to AS3... ... just be redundant and be done with it if you're short on time. :)
also - I advise not using the timeline for this (no 'gotoAndStop' stuff... just call a function based on which button you press that sets the alpha / visibility for the images)... ... if you want the images to fade-up / down - take a moment and check www.greensock.com - download and utilize either tweenMax or tweenLight... both are tweening engines that allow you to fade up / down based on time.
- using 'visible' is important as the flash player won't redraw / consider that MC visible - if you just use 'alpha'... the image is...PonyBoy
- still considered by the player and is 'redrawn'... using more processor / resourcesPonyBoy
- lots to swallow - I know... :)
AS3 requires some study / understanding regardless of what you're doing. Good Luck! :)PonyBoy
- designmachine0
Flash rules what's wrong with apple?
- OBBTKN0
Thanks a lot guys... i´ve not done anything complex in Flash for years, and now the AS3 context is killing me ;)
- OBBTKN0
Hi guys...
I´ve recoded the thing to that:
stop();
var myImageLoader:Loader = new Loader();
var myImageLocation:URLRequest = new URLRequest("IMG/opcion.png");var myImageLoader2:Loader = new Loader();
var myImageLocation2:URLRequest = new URLRequest("IMG/opcion2.png");var myImageLoader3:Loader = new Loader();
var myImageLocation3:URLRequest = new URLRequest("IMG/opcion3.png");var myImageLoader4:Loader = new Loader();
var myImageLocation4:URLRequest = new URLRequest("IMG/opcion4.png");btn1.addEventListener(MouseEvent...
function op1(event:MouseEvent):void{
myImageLoader.load(myImageLocati...
mc.addChild(myImageLoader);
}btn2.addEventListener(MouseEvent...
function op2(event:MouseEvent):void{
myImageLoader2.load(myImageLocat...
mc.addChild(myImageLoader2);
}btn3.addEventListener(MouseEvent...
function op3(event:MouseEvent):void{
myImageLoader3.load(myImageLocat...
mc.addChild(myImageLoader3);
}btn4.addEventListener(MouseEvent...
function op4(event:MouseEvent):void{
myImageLoader4.load(myImageLocat...
mc.addChild(myImageLoader4);
}But the problem now is i need to removechild all the images except the loaded one. Can anyone help on this?
TA
- PonyBoy0
removeChild(myImageLoader#);
- Scroogeken0
Wouldn't an array w/the images/buttons be the way to go?
- OBBTKN0
Yes, for sure...i insert the myImageLoader number there and will remove it, but if it´s not loaded?
- PonyBoy0
take a look at the Loader Class documentation - you'll find it's simple to check if an image is loaded or not.
This is a respectable write-up on the different type of eventListeners for the Loader class: http://www.republicofcode.com/tu…
I suggest using the 'progressEvent' listener to check if the image is loaded when you goto remove the movieclip...
- OBBTKN0
Thanks man... i´ll check it. ta!
- instrmntl0
u could use a queue loader http://www.functionblog.com/?p=4…
- chrisRG0
the best way IMO to load files in flash:
http://www.greensock.com/loaderm…