Hey there,
Sorry if I’m violating protocol by double-posting but I erred and posted this in the wrong forum to start. Anyway…
I’m trying to use a Lightbox effect to load some images with a click on a swf. To do it I’m using the “ExternalInterface.call” command so the AS3 can communicate with the Javascript (where the Lightbox code is).
I found a couple of tutorials that walk through this and, best I can tell, I’m doing it correctly. When I reconstruct what they are doing with just one image, everything is okay. When I take that concept and bring it into a Custom Class I’m using for the larger project, that same syntax is giving me an “1120: Access of Undefined Property…”
Code is below. It’s not too elegant (because I’m not very good at AS, but it works… or at least I know it did because in the lines where I’m trying to use the ExternalInterface call to the lightbox effect, I previously had a URL call and it fucntioned properly)
The relevant lines are about halfway down the page. Can’t figure out what’s wrong here as, like I said, the same code works outside of the Custom Class.
Any help is much appreciated.
package
{
import flash.display.*;
import flash.display.Stage;
import flash.events.*;
import flash.text.*;
import flash.net.*;
import caurina.transitions.Tweener;
import gs.TweenMax;
public class LightBoxTest extends MovieClip
{
private const RECT_HEIGHT:Number = 25; //(for height at 225)
private const RECT_WIDTH:Number = 10;
private const TWEEN_LENGTH:Number = .85;
private const COLUMN_DELAY:Number = .05;
//private var mc:Test;
private var mMask:Sprite;
private var imageRequest:URLRequest = new URLRequest("shirts/nippon_shirt_thumb.jpg");
private var imageLoader:Loader = new Loader();
private var link:URLRequest=new URLRequest("http://www.example.com/store");
//vars to add library itmes to the stage
private var totalBar_mc:totalBar = new totalBar;
private var background_mc:Background = new Background;
private var areaOne_mc:ActionArea = new ActionArea;
private var areaTwo_mc:ActionArea = new ActionArea;
private var thumbOver_mc:thumbOver = new thumbOver;
private var shirtOver_mc:shirtOver = new shirtOver;
//var for setting if/then for the 2-click button
private var p:Number = 0;
public function LightBoxTest()
{
init();
}
private function init()
{
addChildAt(background_mc, 0);
background_mc.x = 0;
background_mc.y = 0;
imageLoader.load(imageRequest);
//mc = new imageLoader(); //'imageLoader' was 'Test'
addChild(imageLoader); //re-revomed "stage." and "At" and "1" (and now it works!)
imageLoader.x = 0;//starting x position for image
imageLoader.y = 0;//starting y position for image
imageLoader.cacheAsBitmap = true;
//imageLoader.alpha = .5
addChildAt(totalBar_mc, 2);
totalBar_mc.x = 130;
totalBar_mc.y = 212;
addChildAt(thumbOver_mc, 3);
thumbOver_mc.x = 87;
thumbOver_mc.y = 212;
thumbOver_mc.alpha = 0;
addChildAt(shirtOver_mc, 3);
shirtOver_mc.x = 172;
shirtOver_mc.y = 212;
shirtOver_mc.alpha = 0;
addChildAt(areaOne_mc, 5);
areaOne_mc.x = 87;
areaOne_mc.y = 212;
areaOne_mc.alpha = 0;
addChildAt(areaTwo_mc, 4);
areaTwo_mc.x = 170;
areaTwo_mc.y = 212;
areaTwo_mc.alpha = 0;
mMask = new Sprite();
mMask.x = imageLoader.x
mMask.y = imageLoader.y;
mMask.cacheAsBitmap = true;
imageLoader.mask = mMask;
areaOne_mc.buttonMode = true;
areaTwo_mc.buttonMode = true;
addChildAt(imageLoader, 1);
addChild(mMask);
areaOne_mc.addEventListener(MouseEvent.MOUSE_OVER, onInRollOne);
areaOne_mc.addEventListener(MouseEvent.MOUSE_OUT, onOutRollOne);
areaTwo_mc.addEventListener(MouseEvent.MOUSE_OVER, onInRollTwo);
areaTwo_mc.addEventListener(MouseEvent.MOUSE_OUT, onOutRollTwo);
areaTwo_mc.addEventListener(MouseEvent.CLICK, onClick01);
areaOne_mc.addEventListener(MouseEvent.CLICK, onClick02);
}
public function onClick01(event:MouseEvent):void
{
ExternalInterface.call("Design_Gallery", "/images/britta.jpg", "[caption here]");
}
private function onInRollOne(m:MouseEvent):void
{
//alphaIn(imageLoader);
TweenMax.to(thumbOver_mc, .4, {alpha:1, overwrite:true});
}
//I'm separating the button action and the mouse click to get the alpha fade
private function onClick02(m:MouseEvent)
{
if (p == 0){
//So on mouse click the image fades in
alphaIn(imageLoader);
p++;
}
else{
alphaOut(imageLoader);
p = 0;
}
//commented out the menu button fade as that was handled above
//TweenMax.to(thumbOver_mc, .4, {alpha:1, overwrite:true});
trace("Hooray, it works...");
///trace(getChildIndex(imageLoader));
}
private function onOutRollOne(m:MouseEvent)
{
TweenMax.to(thumbOver_mc, .4, {alpha:0, overwrite:true});
}
private function onInRollTwo(m:MouseEvent)
{
TweenMax.to(shirtOver_mc, .4, {alpha:1, overwrite:true});
}
private function onOutRollTwo(m:MouseEvent)
{
TweenMax.to(shirtOver_mc, .4, {alpha:0, overwrite:true});
}
private function alphaIn(imageLoader)
{
//Fade the backround out on rollover
Tweener.addTween(background_mc, {alpha:.2, time:2});
//gunners_mc.alpha = .2; (Commented out)
//line below is probably the culprit as I doubt I'm generating a whole number
var NUM_ROWS = Math.ceil(imageLoader.height/RECT_HEIGHT);
var NUM_COLUMNS = Math.ceil(imageLoader.width/RECT_WIDTH);
for(var i:int = 0; i<NUM_COLUMNS; i++)
{
var mCol:Column = new Column(mMask, imageLoader, i, RECT_WIDTH, RECT_HEIGHT);
//setting the initial fade value
mCol.fade = 0;
Tweener.addTween(mCol, {fade:1, time:TWEEN_LENGTH, onUpdate:mCol.drawColumn, delay:i*COLUMN_DELAY, onComplete:finishFunction});
var finishFunction:Function = function()
{
// kill the object
mCol = null;
}
}
}
private function alphaOut(imageLoader)
{
//Fade the backround back up on roll out
Tweener.addTween(background_mc, {alpha:1, time:3});
//gunners_mc.alpha = 1; (Commented out)
var NUM_ROWS = Math.ceil(imageLoader.height/RECT_HEIGHT);
var NUM_COLUMNS = Math.ceil(imageLoader.width/RECT_WIDTH)+1;
trace(imageLoader.width);
//"NUM_COLUMNS -1" was "NUM_COLUMNS" (changed to make it cycle through only 26 times
for(var i:int = 0; i <NUM_COLUMNS-1; i++)
{
var mCol:Column = new Column(mMask, imageLoader, i, RECT_WIDTH, RECT_HEIGHT);
// setting the initial fade value
///trace(i);
mCol.fade = 1;
Tweener.addTween(mCol, {fade:0, time:TWEEN_LENGTH, onUpdate:mCol.fadeColumn, delay:i*COLUMN_DELAY, onComplete:finishFunction});
var finishFunction:Function = function()
{
// kill the object
mCol = null;
}
}
}
}
}