I’ve been working on this one problem for weeks now. I have made small simple AS3 and As2 projects, but nothing to this extent. I have created a carousel and I need my swf to play only when it is in the front position. I have a function checkFront that is called on on complete, I just don’t know how to call that specific file from my xml to tell it to play when it is its position.
here is my document class:
package {
import caurina.transitions.Tweener;
import com.becca.Carousel;
import com.becca.CarouselItem;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.events.KeyboardEvent;
public class CarouselDoc extends MovieClip {
// on stage of .fla
public var rightAd:MovieClip;
public var leftAd:MovieClip;
//public var right_mc:MovieClip;
//public var left_mc:MovieClip;
public var holder_mc:MovieClip;
public var loading_txt:TextField;
public static const XML_URL:String = "images.xml";
private var carousel:Carousel;
private var imageList:XMLList;
private var numImages:int;
private var currentImage:int = 0;
public function CarouselDoc():void {
carousel = new Carousel(500, 250, 220);
carousel.useBlur = false;
holder_mc.addChild(carousel);
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
rightAd.addEventListener(MouseEvent.CLICK, leftClickHandler);
leftAd.addEventListener(MouseEvent.CLICK, rightClickHandler);
//right_mc.addEventListener(MouseEvent.CLICK, rightClickHandler);
//left_mc.addEventListener(MouseEvent.CLICK, leftClickHandler);
var uloader:URLLoader = new URLLoader();
uloader.addEventListener(Event.COMPLETE, xmlHandler);
uloader.addEventListener(IOErrorEvent.IO_ERROR, xmlHandler);
uloader.load(new URLRequest(XML_URL));
}
private function xmlHandler(event:*):void {
event.currentTarget.removeEventListener(Event.COMPLETE, xmlHandler);
event.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR, xmlHandler);
if (event is IOErrorEvent) {
loading_txt.text = "could not load xml file";
} else {
var xml:XML = new XML(event.currentTarget.data);
imageList = xml..image;
numImages = imageList.length();
loadImage();
}
}
private function loadImage():void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imageHandler);
loader.load(new URLRequest(imageList[currentImage].toString()));
}
private function imageHandler(event:*):void {
event.currentTarget.removeEventListener(Event.COMPLETE, imageHandler);
event.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR, imageHandler);
if (event is IOErrorEvent) {
loading_txt.text = "could not load image" + currentImage;
} else {
var image:Loader = event.currentTarget.loader;
carousel.addItem(image);
}
if (++currentImage < numImages){
loadImage();
} else {
loading_txt.text = "";
}
}
private function rightClickHandler(event:MouseEvent):void {
carousel.targetRotation += 360 / carousel.numItems;
Tweener.addTween(carousel, { zRotation:carousel.targetRotation, time:1, transition:"easeInCubic", onComplete:checkFront } );
}
private function leftClickHandler(event:MouseEvent):void {
carousel.targetRotation -= 360 / carousel.numItems;
Tweener.addTween(carousel, { zRotation:carousel.targetRotation, time:1, transition:"easeInCubic",onComplete:checkFront } );
}
private function keyHandler(event:KeyboardEvent):void {
if(event.keyCode==37){
carousel.targetRotation -= 360 / carousel.numItems;
Tweener.addTween(carousel, { zRotation:carousel.targetRotation, time:1, transition:"easeInCubic",onComplete:checkFront } );
} else if (event.keyCode==39){
carousel.targetRotation += 360 / carousel.numItems;
Tweener.addTween(carousel, { zRotation:carousel.targetRotation, time:1, transition:"easeInCubic",onComplete:checkFront } );
}
}
private function checkFront() {
}
}
}
and my xml:
<menuItems>
<item>
<image>pics/VS Home Page Animation.swf</image>
<link>http://www.ema-eda.com/training/seminars.aspx</link>
</item>
<item>
<image>pics/CadenceWebinar.jpg</image>
<link>http://www.cadence.com/cadence/events/Pages/allegro_webinar_series.aspx?CMP=cbnr20081006</link>
</item>
<item>
<image>pics/Class.jpg</image>
<link>http://www.ema-eda.com/training/orcadtraining.aspx</link>
</item>
</menuItems>