Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 fade in out external .png or movie clip

New Here ,
Oct 05, 2013 Oct 05, 2013

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

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 05, 2013 Oct 05, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 05, 2013 Oct 05, 2013

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2013 Oct 06, 2013

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2013 Oct 06, 2013

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 10, 2013 Oct 10, 2013
LATEST

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2013 Oct 06, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines