Jump to content


Image rotator error

  • Please log in to reply
No replies to this topic

#1 oz_87


    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 02 September 2009 - 10:17 AM

When i load the swf file i get the following error;

TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChild()
at local.display::ImageSequence3D/updateRotation()
at local.display::ImageSequence3D/render()
at local.display::ImageSequence3D/mouseMoveHandler()

the .as file:

package local.display
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.IOErrorEvent
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.ui.Mouse;

import fl.transitions.Tween;
import fl.transitions.easing.Regular;

import local.display.PieLoader;

public class ImageSequence3D extends MovieClip
// more will be more sensitive, less will be less (use decimals)
private static var SENSITIVITY: Number = 2;

private static var isDragging: Boolean = false;
private static var inWaiting: ImageSequence3D = null;

private var ready: Boolean = false;
private var bitmaps: Array;
private var divisor: int;
private var currentIndex: int = -1;
private var loadedIndex: int = -1;
private var _draggable: Boolean = false;
private var rotTween: Tween;
private var fadeTween: Tween;
private var pieLoader: PieLoader = new PieLoader();
private var images: Array;
private var rotY: Number = 0;
private var closedHandCursor: ClosedHandCursor = new ClosedHandCursor();
private var openHandCursor: OpenHandCursor = new OpenHandCursor();

// the constructor function sets up the clip
public function ImageSequence3D() : void
// remove the graphics for the drag and drop movie clip
while (numChildren > 0)

mouseChildren = false;

// here I am automatically calling initialize with a predetermined path to the xml
// if you want your own path change it here. Or you can comment this out and call
// initialize yourself manually when you want the object to start. It only will
// initialize once on stage, and this is necessary!!
if (stage == null) addEventListener(Event.ADDED_TO_STAGE, autoInitialize);
else autoInitialize(null);

mouseEnabled = false;

// this function will start the object loading the xml, and once ready after loading stuff it will play
public function initialize(xmlPath: String) : void
var loader: URLLoader = new URLLoader(new URLRequest(xmlPath));
loader.addEventListener(Event.COMPLETE, xmlReady);
loader.addEventListener(IOErrorEvent.IO_ERROR, trace);

// calling this starts up the ImageSequence3D. It will load all the images and then display
public function show(images: Array) : void
this.images = images;
bitmaps = new Array();
divisor = 360 / images.length;

// this starts it loading, loading will be one at a time

// this is the getter and setter for the rotationY property, which sets the rotation of the object
public function set rotationY(val: Number) : void
rotY = val;
public function get rotationY() : Number { return rotY; }

// this sets whether it's draggable or not
public function set draggable(val: Boolean) : void
if (!ready)
return void;

if (val && !_draggable)
addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
addEventListener(MouseEvent.ROLL_OVER, mouseOverHandler);
addEventListener(MouseEvent.ROLL_OUT, mouseOutHandler);
else if (!val && _draggable)
removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
removeEventListener(MouseEvent.ROLL_OVER, mouseOverHandler);
removeEventListener(MouseEvent.ROLL_OUT, mouseOutHandler);

_draggable = val;
public function get draggable() : Boolean { return _draggable; }

// this will cause the object to snap back to 0 rotation
public function snapBack(time: Number) : void
if (rotTween)

while (rotY < 0) rotY += 360;
rotY = rotY % 360;

rotTween = new Tween(this, "rotationY", Regular.easeInOut, rotationY, 0, time, true);

public function render() : void
// if the loading is not ready, then place the x and y, but don't get rid of the skew
// and don't update the showing image in the sequence
if (!ready)
return void;

// this will use the rotY value to update what image in the sequence should show

private function autoInitialize(event: Event) : void
if (event)
removeEventListener(Event.ADDED_TO_STAGE, autoInitialize);


// once the xml is finished loading, this gets called, starting the individual loading for the objects
private function xmlReady(event: Event) : void
// remove the old listener to pick up our old trash
event.target.removeEventListener(Event.COMPLETE, xmlReady);

var xml = new XML(event.target.data);
var imgs: Array = new Array();
for each (var image: XML in xml.image)
imgs.push(String([email protected]));

// show the image sequence

// this is for the staggered loading of the images, which is important for keeping track of the percentage
private function loadNext(event: Event = null) : void

// if it's not the first one, run this
if (event != null)
event.target.removeEventListener(Event.COMPLETE, loadNext);

// get the map, center it and turn on it's smoothing
var map: Bitmap = event.target.loader.content as Bitmap;
map.x = -map.width / 2;
map.y = -map.height / 2;
map.smoothing = true;

// if the last one was done when this was called, run this
if (loadedIndex == images.length)
ready = true;

// activate the object
draggable = true;

// let the parent know that it's done
dispatchEvent(new Event(Event.COMPLETE));

mouseEnabled = true;

// return void to avoid having it try to load more, since this was the last one
return void;

// load the next image
var loader: Loader = new Loader()
loader.load(new URLRequest(images[loadedIndex]));
pieLoader.setLoaderMirror(loader, 100 / images.length, 100 / images.length * loadedIndex, loadedIndex == images.length - 1);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadNext);

private function updateRotation() : void
var rY: Number = rotY;

while(rY < 0) rY += 360; while(rY > 359) rY -= 360;
var newIndex: int = (rY - (rY % divisor)) / divisor;

// if it doesn't need to change, just do nothing
if (newIndex == currentIndex) return void;


if (currentIndex > -1 && contains(bitmaps[currentIndex]))

currentIndex = newIndex;

private function fadeIn() : void
if (fadeTween)

fadeTween = new Tween(this, "alpha", Regular.easeOut, 0, alpha, .5, true);

private var origX: Number;
private var origRotY: Number;
internal function mouseOverHandler(event: MouseEvent) : void
if (isDragging)
inWaiting = this;
return void;

stage.addEventListener(MouseEvent.MOUSE_MOVE, cursorFollow);
if (!stage.contains(closedHandCursor))
private function mouseOutHandler(event: MouseEvent) : void
inWaiting = null;
if (isDragging) return void;

stage.removeEventListener(MouseEvent.MOUSE_MOVE, cursorFollow);

if (stage.contains(openHandCursor))
private function cursorFollow(event: MouseEvent) : void
closedHandCursor.x = openHandCursor.x = event.stageX;
closedHandCursor.y = openHandCursor.y = event.stageY;
closedHandCursor.visible = openHandCursor.visible = true;
private function mouseDownHandler(event: MouseEvent) : void
isDragging = true;

origX = mouseX;
origRotY = rotY;
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

if (stage.contains(openHandCursor))
private function mouseMoveHandler(event: MouseEvent) : void
var delta: Number = mouseX - origX;
rotY = delta * SENSITIVITY + origRotY;
private function mouseUpHandler(event: MouseEvent) : void
stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

if (stage.contains(closedHandCursor))

if (hitTestPoint(event.stageX, event.stageY))

isDragging = false;
if (inWaiting && inWaiting.draggable) inWaiting.mouseOverHandler(event);

if somebody can i help i would be extremely greatful.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users