Calling a function on maintimeline from class (AS3)

This is personally the best way I think...

Uses Events, Enumeration and Classes :slight_smile:

“Class Demo”:http://msfx.co.uk/temp/ClassDemo.zip

and you get to learn more about events :slight_smile:

can u save as cs3 mate?

thought I did, gimme 5 then re-try… :slight_smile:

done :slight_smile:

done :)

legend. thanks for all the help man!
hav a good wkend!

done :)

legend. thanks for all the help man!
hav a good wkend!

NP. You too :slight_smile:

Wondering if anyone could help me. I’m trying to basically do the same thing here. I need to call a class on a main timeline in my flash file.

//My class file looks like this here:
package {

import caurina.transitions.Tweener;
import com.onebyonedesign.td.OBO_3DCarousel;
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;

/**
* Just a test of the OBO_3DCarousel class
* @author Devon O.
*/
public class CarouselTest extends MovieClip {
	
	// on stage of .fla
	public var tab1:MovieClip;
	public var tab2:MovieClip;
	public var tab3:MovieClip;
	public var right_mc:MovieClip;
	public var left_mc:MovieClip;
	public var loading_txt:TextField;

	public static const XML_URL:String = "images.xml";
	
	private var _carousel:OBO_3DCarousel;
	private var _imageList:XMLList;
	private var _numImages:int;
	private var _currentImage:int = 0;
	
	public function CarouselTest():void {
		_carousel = new OBO_3DCarousel(350, 370, 360);//Foc, Rad, Z;
		_carousel.useBlur = true;
		_carousel.y = 100;
		_carousel.x = 490;
		addChild(_carousel);
		
		tab1.buttonMode = true;
		tab2.buttonMode = true;
		tab3.buttonMode = true;
		right_mc.buttonMode = true;
		left_mc.buttonMode = true;
		
		tab1.addEventListener(MouseEvent.CLICK, tab1click);
		tab2.addEventListener(MouseEvent.CLICK, tab2click);
		tab3.addEventListener(MouseEvent.CLICK, tab3click);
		right_mc.addEventListener(MouseEvent.CLICK, rightClickHandler);
		left_mc.addEventListener(MouseEvent.CLICK, leftClickHandler);
		right_mc.addEventListener(MouseEvent.ROLL_OVER, rightRollOver);
		left_mc.addEventListener(MouseEvent.ROLL_OVER, leftRollOver);
		
		loading_txt.text = "loading xml";
		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 {
		loading_txt.text = "loading image " + (_currentImage + 1).toString() + " / " + _numImages.toString();
		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 no " + _currentImage;
		} else {
			var image:Loader = event.currentTarget.loader;
			_carousel.addItem(image);
		}
		
		if (++_currentImage < _numImages){
			loadImage();
		} else {
			loading_txt.text = "complete";
			Tweener.addTween(loading_txt, { alpha:0, time:1, transition:"Linear" } );
		}
	}
  }

}

//on the first frame of my timeline, the code is this:
import CarouselTest;
var cmp:CarouselTest = new CarouselTest();
addChild(cmp);

I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at CarouselTest()
at productpage_v1_fla::MainTimeline/frame1()

Any help would be greatly appreciated…

Just a quick glance it looks like some brackets are out of place. Paste your code at pastie.org and it will be easier for us to read it.