Cutless009
September 10th, 2009, 09:37 AM
Not sure what this error means, but it looks like this:
"Type Coercion failed: cannot convert *object* to *movieClip*"
What Im trying to do is create a new Layer (swc asset, is a movieclip), inside a previous created Layer, and draw on it instead of on the original Layer.
any help? The end goal here is I have squares, circles, and lines, and if I paint a square or circle shape (which are classes, and are added to the canvas using addChild, I cannot change this), I need the lines to paint on top of them if I go back to using the line tool.
//-- Layers --\\
private var layer:Layer;
private var layers:Array;
private var numLayers:int;
private var currentLayer:int;
private var overLayer:MovieClip;
//-- Make Layer --\\
layer = new Layer();
layer.graphics.lineTo(1,1);
canvas.addChild(layer);
layer.currentOverlay = 0;
layers.push(layer);
//-- Set Variables --\\
numLayers ++;
currentLayer = layers.length - 1;
//-- Make Layer Selector --\\
layerBox = new LayerBox;
layerBox.tfLayerBox.text = "Layer " + currentLayer;
layerBox.mouseChildren = false;
layerBox.buttonMode = true;
layerBox.addEventListener(MouseEvent.CLICK, setLayer);
layerBox.addEventListener(MouseEvent.CLICK, editLayer);
layerBox.index = currentLayer;
if (currentLayer == 0)
{
layerBox.tfLayerBox.text = "Main Layer"
}
layerBox.x = 0;
layerBox.y = (-layerBox.height * (numLayers)) + layerCont.height - layerBox.height + 20;
layerCont.addChild(layerBox);
layerBoxes.push(layerBox);
private function startPainting(event:MouseEvent):void
{
canvas.addEventListener(Event.ENTER_FRAME, paint);
canvas.addEventListener(MouseEvent.MOUSE_UP, stopPainting);
layers[currentLayer].graphics.moveTo(canvas.mouseX, canvas.mouseY);
if (layers[currentLayer].numChildren > 1)
{
var overLayer:Layer = new Layer;
layers[currentLayer].addChild(overLayer);
layers[currentLayer].currentOverlay ++;
overLayer = layers[currentLayer].getChildAt(layers[currentLayer].currentOverlay);
}
}
private function paint(event:Event):void
{
var ct:ColorTransform = new ColorTransform;
ct.color = drawColor;
if (drawMode == "line")
{
if(layers[currentLayer].numChildren > 1)
{
overLayer.graphics.lineStyle(drawSize, drawColor, drawAlpha);
overLayer.graphics.lineTo(canvas.mouseX, canvas.mouseY);
}
layers[currentLayer].graphics.lineStyle(drawSize, drawColor, drawAlpha);
layers[currentLayer].graphics.lineTo(canvas.mouseX, canvas.mouseY);
}
"Type Coercion failed: cannot convert *object* to *movieClip*"
What Im trying to do is create a new Layer (swc asset, is a movieclip), inside a previous created Layer, and draw on it instead of on the original Layer.
any help? The end goal here is I have squares, circles, and lines, and if I paint a square or circle shape (which are classes, and are added to the canvas using addChild, I cannot change this), I need the lines to paint on top of them if I go back to using the line tool.
//-- Layers --\\
private var layer:Layer;
private var layers:Array;
private var numLayers:int;
private var currentLayer:int;
private var overLayer:MovieClip;
//-- Make Layer --\\
layer = new Layer();
layer.graphics.lineTo(1,1);
canvas.addChild(layer);
layer.currentOverlay = 0;
layers.push(layer);
//-- Set Variables --\\
numLayers ++;
currentLayer = layers.length - 1;
//-- Make Layer Selector --\\
layerBox = new LayerBox;
layerBox.tfLayerBox.text = "Layer " + currentLayer;
layerBox.mouseChildren = false;
layerBox.buttonMode = true;
layerBox.addEventListener(MouseEvent.CLICK, setLayer);
layerBox.addEventListener(MouseEvent.CLICK, editLayer);
layerBox.index = currentLayer;
if (currentLayer == 0)
{
layerBox.tfLayerBox.text = "Main Layer"
}
layerBox.x = 0;
layerBox.y = (-layerBox.height * (numLayers)) + layerCont.height - layerBox.height + 20;
layerCont.addChild(layerBox);
layerBoxes.push(layerBox);
private function startPainting(event:MouseEvent):void
{
canvas.addEventListener(Event.ENTER_FRAME, paint);
canvas.addEventListener(MouseEvent.MOUSE_UP, stopPainting);
layers[currentLayer].graphics.moveTo(canvas.mouseX, canvas.mouseY);
if (layers[currentLayer].numChildren > 1)
{
var overLayer:Layer = new Layer;
layers[currentLayer].addChild(overLayer);
layers[currentLayer].currentOverlay ++;
overLayer = layers[currentLayer].getChildAt(layers[currentLayer].currentOverlay);
}
}
private function paint(event:Event):void
{
var ct:ColorTransform = new ColorTransform;
ct.color = drawColor;
if (drawMode == "line")
{
if(layers[currentLayer].numChildren > 1)
{
overLayer.graphics.lineStyle(drawSize, drawColor, drawAlpha);
overLayer.graphics.lineTo(canvas.mouseX, canvas.mouseY);
}
layers[currentLayer].graphics.lineStyle(drawSize, drawColor, drawAlpha);
layers[currentLayer].graphics.lineTo(canvas.mouseX, canvas.mouseY);
}