Copy link to clipboard
Copied
Hi there all,
I am trying to code a light box in AS3. I can get it to work on 1 click of a specified movie clip, but i have 6 movie clips on my stage myCLIP_1 .to.myCLIP_6 with 6 different targets m1 .to. m6. I just cant get it to work for all 6 buttons at once. I am at my wits end..... please please help.
thanks in advance
p.s. I have only been coding for 6 months.
CAN'T paste the code i have already
Copy link to clipboard
Copied
You'll need to show your code, otherwise you need to show/describe how you coded the different buttons in some manner. Consider using pastebin.com if you canb't figure out how to paste it into your posting.
If you cannot show your code due to contractual reasons, then create code like it and show that. You may only need to display two of the six for the problem to be determinable.
Do you get any error messages? If so, you need to include those as well.
Copy link to clipboard
Copied
6 movie clips on stage myCLIP_1 ..to..myCLIP_6
6 images in MOVIES/1/ .. m1 ..to..m6
this works for 1 movie but cant get it to fork for all 6
hope you can help
stop();
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.MovieClip;
var lightbox : Sprite;
var darkener : Shape;
var thumbnail = myCLIP_1
thumbnail.addEventListener(MouseEvent.CLICK, onThumbnailClick);
function onThumbnailClick(event:MouseEvent):void
{
darkener = new Shape();
darkener.graphics.beginFill(0x000000, .6);
darkener.graphics.drawRect(0,0,320,280);
darkener.graphics.endFill();
addChild(darkener);
TweenLite.from(darkener, .5, {alpha: 0});
loadImage("MOVIES/1/m1.png");
}
function loadImage(url : String) : void
{
var loader : Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loader.load(new URLRequest(url));
}
function onImageLoaded(event:Event):void
{
thumbnail.mouseEnabled = false;
LoaderInfo(event.target).removeEventListener(Event.COMPLETE, onImageLoaded);
var image:Bitmap = Bitmap(Loader(LoaderInfo(event.target).loader).content);
image.x = image.y = 0;
lightbox = new Sprite();
lightbox.graphics.beginFill(0xFFFFFF, 1);
lightbox.graphics.drawRect(0,0,image.width, image.height);
lightbox.graphics.endFill();
lightbox.x = 10;
lightbox.y = 10;
lightbox.buttonMode = true;
lightbox.addChild(image);
addChild(lightbox);
TweenLite.from(lightbox, 1, {alpha:0});
lightbox.addEventListener(MouseEvent.CLICK, onCloseLightbox);
}
function onCloseLightbox(event:MouseEvent):void
{
lightbox.mouseEnabled = false;
var timeline : TimelineLite = new TimelineLite({onComplete: removeLightbox});
timeline.insert(new TweenLite(lightbox, 1, {alpha:0}));
timeline.append(new TweenLite(darkener, .3, {alpha:0}));
}
function removeLightbox():void
{
lightbox.removeEventListener(MouseEvent.CLICK, onCloseLightbox);
removeChild(lightbox);
lightbox = null;
thumbnail.mouseEnabled = true;
}
Copy link to clipboard
Copied
I only see one object with code for clicking. If that is the code that works, that is not going to help to solve the problem.
How do you implement the code for one of the objects that does not work?
Copy link to clipboard
Copied
nearly fixed it I think lol all 6 movie clip buttons work but only displays image 6 on all of them.
also if I click just outside the loaded image the child wont disappear.
hope you can help
stop();
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
var lightbox : Sprite;
var darkener : Shape;
var myArray : Array =
[
{label:myCLIP_1, path:"MOVIES/1/m1.png"},
{label:myCLIP_2, path:"MOVIES/1/m2.png"},
{label:myCLIP_3, path:"MOVIES/1/m3.png"},
{label:myCLIP_4, path:"MOVIES/1/m4.png"},
{label:myCLIP_5, path:"MOVIES/1/m5.png"},
{label:myCLIP_6, path:"MOVIES/1/m6.png"},
];
for each (var obj in myArray)
{
var m = obj.label;
m.path = obj.path;
m.addEventListener(MouseEvent.CLICK, onClick);
}
function onClick(event:MouseEvent):void
{
darkener = new Shape();
darkener.graphics.beginFill(0x000000, .6);
darkener.graphics.drawRect(0,0,320,280);
darkener.graphics.endFill();
addChild(darkener);
TweenLite.from(darkener, .5, {alpha: 0});
loadImage(m.path);
}
function loadImage(url : String) : void
{
var loader : Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loader.load(new URLRequest(url));
}
function onImageLoaded(event:Event):void
{
m.mouseEnabled = false;
LoaderInfo(event.target).removeEventListener(Event.COMPLETE, onImageLoaded);
var image:Bitmap = Bitmap(Loader(LoaderInfo(event.target).loader).content);
image.x = image.y = 0;
lightbox = new Sprite();
lightbox.graphics.beginFill(0xFFFFFF, 1);
lightbox.graphics.drawRect(0,0,300,260);
lightbox.graphics.endFill();
lightbox.x = 10;
lightbox.y = 10;
lightbox.buttonMode = true;
lightbox.addChild(image);
addChild(lightbox);
TweenLite.from(lightbox, 1, {alpha:0});
lightbox.addEventListener(MouseEvent.CLICK, onCloseLightbox);
}
function onCloseLightbox(event:MouseEvent):void
{
lightbox.mouseEnabled = false;
var timeline : TimelineLite = new TimelineLite({onComplete: removeLightbox});
timeline.insert(new TweenLite(lightbox, 1, {alpha:0}));
timeline.append(new TweenLite(darkener, .3, {alpha:0}));
}
function removeLightbox():void
{
lightbox.removeEventListener(MouseEvent.CLICK, onCloseLightbox);
removeChild(lightbox);
lightbox = null;
m.mouseEnabled = true;
}
Copy link to clipboard
Copied
I think the problem arises from using "m" in any function after having defined its value in the loop at the start. m is the last object assigned any time after that point. Instead of using m any time later, use the object itself.
function onClick(event:MouseEvent):void
{
darkener = new Shape();
darkener.graphics.beginFill(0x000000, .6);
darkener.graphics.drawRect(0,0,320,280);
darkener.graphics.endFill();
addChild(darkener);
TweenLite.from(darkener, .5, {alpha: 0});
loadImage(Object(event.currentTarget).path);
}
Copy link to clipboard
Copied
I am replying to you earlier post so that you can still go in and edit your latest. As is it is illegible as code due to no formatting.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now