Question
5000: The class 'privatePkg.Camera' must subclass 'flash.display.MovieClip' since it is linked to a
to start this off, I have never had this issue before and I never touch any of the coding in my animations, just use tweening to pan my camera and to change tints and opacities of my objects. However, right now for some reason my camera and opacities of in my animations have just flat out stopped working and I have two similar errors going on that include this error code. Please someone help! I don't know how coding works. I have added the the whole script in this message.
package privatePkg
{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.geom.Matrix;
import flash.geom.Transform;
import flash.geom.Matrix3D;
import flash.display.MovieClip;
import flash.geom.ColorTransform;
import flash.events.Event;
import fl.motion.Color;
import fl.motion.AdjustColor;
import flash.filters.ColorMatrixFilter;
import privatePkg.CameraGuide;
/* container type value
public static const CAMERA = 0;
public static const LAYER_PROPERTIES = 1;
public static const LAYER_OBJECT = 2;
*/
public class ___Camera___ extends MovieClip
{
private var centerX: Number, centerY: Number;
private var camAxisX: Number, camAxisY: Number;
private var camAPIcalled: Boolean;
private var cameraGuide:CameraGuide;
private const MIN_X = -10000;
private const MIN_Y = -10000;
private const MIN_Z = -5000;
private const MAX_X = 10000;
private const MAX_Y = 10000;
private const MAX_Z = 10000;
private const MIN_ZOOM = 1;
private const MAX_ZOOM = 10000;
private const MIN_RGB = 0;
private const MAX_RGB = 255;
private const MIN_BRIGHTNESS = -100;
private const MAX_BRIGHTNESS = 100;
private const MIN_CONTRAST = -100;
private const MAX_CONTRAST = 100;
private const MIN_SATURATION = -100;
private const MAX_SATURATION = 100;
private const MIN_HUE = -180;
private const MAX_HUE = 180;
private const MAX_angle = 180;
private const MIN_angle = -179;
[Inspectable(type = "Number", defaultValue = 0)]
public var containerType: Number = 0;
[Inspectable(type = "Number", defaultValue = 0)]
public var layerDepth: Number = 0;
public function ___Camera___(w:Number = 0, h:Number = 0)
{
visible = false;
cameraGuide = new CameraGuide();
centerX = centerY = 0;
if(h<=0 || w<=0)
{
if(parent != null)
{
centerX = parent.stage.stageWidth / 2;
centerY = parent.stage.stageHeight / 2;
}
}
else
{
centerX = w/2;
centerY = h/2;
}
camAxisX = centerX;
camAxisY = centerY;
camAPIcalled = false;
if( parent != null )
init();
}
public function init()
{
addEventListener(Event.ENTER_FRAME, cameraEnterFrame);
addEventListener(Event.EXIT_FRAME, cameraControl);
addEventListener(Event.REMOVED_FROM_STAGE, resetStage);
}
private function camAPIinit()
{
camAxisX = this.x;
camAxisY = this.y;
// to match the PI for zoom
/*if(this.scaleX != 1 || this.scaleY != 1)
{
var initTx = (this.x - centerX)*(1/this.scaleX - 1);
var initTy = (this.y - centerY)*(1/this.scaleY - 1);
camAxisX += initTx;
camAxisY += initTy;
}*/
camAPIcalled = true;
}
public function moveBy(tx: Number, ty: Number, tz: Number = 0): void
{
if(!camAPIcalled)
{
camAPIinit();
}
var position = getCamPosition();
var rotAngle: Number = getRotation()*Math.PI/180;
var sinTheta: Number = Math.sin(rotAngle);
var cosTheta: Number = Math.cos(rotAngle);
var offX: Number = tx*cosTheta + ty*sinTheta;
var offY: Number = ty*cosTheta - tx*sinTheta;
camAxisX = camAxisX - tx;
camAxisY = camAxisY - ty;
var posX: Number = position.x + offX;
var posY: Number = position.y + offY;
this.x = centerX - posX;
this.y = centerY - posY;
if (advancedLayersEnabled(parent))
this["layerDepth"] += tz;
stage.invalidate();
}
public function setPosition(posX: Number, posY: Number, posZ: Number = 0): void
{
if(!camAPIcalled)
camAPIcalled = true;
if(posX < MIN_X)
posX = MIN_X;
else if(posX > MAX_X)
posX = MAX_X;
if(posY < MIN_Y)
posY = MIN_Y;
else if(posY > MAX_Y)
posY = MAX_Y;
if(posZ < MIN_Z)
posZ = MIN_Z;
else if(posZ > MAX_Z)
posZ = MAX_Z;
var rotAngle: Number = getRotation()*Math.PI/180;
var sinTheta: Number = Math.sin(rotAngle);
var cosTheta: Number = Math.cos(rotAngle);
var offX: Number = posX*cosTheta + posY*sinTheta;
var offY: Number = posY*cosTheta - posX*sinTheta;
this.x = centerX - offX;
this.y = centerY - offY;
camAxisX = centerX - posX;
camAxisY = centerY - posY;
if (advancedLayersEnabled(parent))
this["layerDepth"] = posZ;
stage.invalidate();
}
private function getCamPosition(): Object
{
var loc: Object = new Object();
loc["x"] = centerX - this.x;
loc["y"] = centerY - this.y;
loc["z"] = this["layerDepth"];
return loc;
}
public function getPosition(): Object
{
var loc: Object = new Object();
if(!camAPIcalled)
{
loc["x"] = centerX - this.x;
loc["y"] = centerY - this.y;
loc["z"] = this["layerDepth"];
return loc;
}
loc["x"] = centerX - camAxisX;
loc["y"] = centerY - camAxisY;
loc["z"] = this["layerDepth"];
return loc;
}
public function resetPosition(): void
{
setPosition(0, 0, 0);
}
public function zoomBy(zoom: Number): void
{
setZoom( (getZoom() * zoom) / 100);
}
public function setZoom(zoom: Number): void
{
if(!camAPIcalled)
{
camAPIinit();
}
if(zoom < MIN_ZOOM)
zoom = MIN_ZOOM;
else if(zoom > MAX_ZOOM)
zoom = MAX_ZOOM;
this.scaleX = 100/zoom;
this.scaleY = 100/zoom;
stage.invalidate();
}
public function getZoom(): Number
{
return (100/this.scaleX);
}
public function resetZoom(): void
{
setZoom(100);
}
public function rotateBy(angle: Number): void
{
if(!camAPIcalled)
camAPIinit();
setRotation(getRotation() + angle);
}
public function setRotation(angle: Number): void
{
if(angle < MIN_angle)
angle = MIN_angle;
else if(angle > MAX_angle)
angle = MAX_angle;
if(!camAPIcalled)
camAPIinit();
this.rotation = -angle;
stage.invalidate();
}
public function getRotation(): Number
{
return -this.rotation;
}
public function resetRotation(): void
{
setRotation(0);
}
public function setTint(tintColor: Number, tintPercent: Number): void
{
var color: Color = new Color();
color.setTint(tintColor, tintPercent / 100);
this.transform.colorTransform = color;
stage.invalidate();
}
public function setTintRGB(red: Number, green: Number, blue: Number, tintPercent: Number): void
{
if(red < MIN_RGB)
red = MIN_RGB;
if(red > MAX_RGB)
red = MAX_RGB;
if(green < MIN_RGB)
green = MIN_RGB;
if(green > MAX_RGB)
green = MAX_RGB;
if(blue < MIN_RGB)
blue = MIN_RGB;
if(blue > MAX_RGB)
blue = MAX_RGB;
if(tintPercent < 0)
tintPercent = 0;
if(tintPercent > 100)
tintPercent = 100;
var tintColor: uint = 0;
tintColor = tintColor | red << 16;
tintColor = tintColor | green << 8;
tintColor = tintColor | blue;
setTint(tintColor, tintPercent);
}
public function getTint():Object
{
var tintObjRGB = getTintRGB();
var tintObj = new Object();
tintObj['percent'] = tintObjRGB['percent'];
var tintColor: uint = 0;
tintColor = tintColor | tintObjRGB['red'] << 16;
tintColor = tintColor | tintObjRGB['green'] << 8;
tintColor = tintColor | tintObjRGB['blue'];
tintObj['color'] = tintColor;
return tintObj;
}
public function getTintRGB():Object
{
var tintObj:Object = new Object();
tintObj['percent'] = 0;
tintObj['red'] = 0;
tintObj['green'] = 0;
tintObj['blue'] = 0;
if(this.transform != null && this.transform.colorTransform != null)
{
var percent = 100.0 * (1 - this.transform.colorTransform.redMultiplier);
tintObj['percent'] = percent;
tintObj['red'] = (this.transform.colorTransform.redOffset*100.0)/percent;
tintObj['green'] = (this.transform.colorTransform.greenOffset*100.0)/percent;
tintObj['blue'] = (this.transform.colorTransform.blueOffset*100.0)/percent;
}
return tintObj;
}
public function resetTint()
{
setTint(0, 0);
}
public function setColorFilter(brightness: Number, contrast: Number, saturation: Number, hue: Number): void
{
if(brightness < MIN_BRIGHTNESS)
brightness = MIN_BRIGHTNESS;
else if(brightness > MAX_BRIGHTNESS)
brightness = MAX_BRIGHTNESS;
if(contrast < MIN_CONTRAST)
contrast = MIN_CONTRAST;
else if(contrast > MAX_CONTRAST)
contrast = MAX_CONTRAST;
if(saturation < MIN_SATURATION)
saturation = MIN_SATURATION;
else if(saturation > MAX_SATURATION)
saturation = MAX_SATURATION;
if(hue < MIN_HUE)
hue = MIN_HUE;
else if(hue > MAX_HUE)
hue = MAX_HUE;
var adjColorFilter: AdjustColor = new AdjustColor();
adjColorFilter.brightness = brightness;
adjColorFilter.contrast = contrast;
adjColorFilter.saturation = saturation;
adjColorFilter.hue = hue;
var mMatrix: Array = adjColorFilter.CalculateFinalFlatArray();
var filterMat: ColorMatrixFilter = new ColorMatrixFilter(mMatrix);
this.filters = [filterMat];
stage.invalidate();
}
public function resetColorFilter()
{
this.filters = null;
}
public function reset()
{
resetZoom();
resetRotation();
resetPosition();
resetTint();
resetColorFilter();
unpinCamera();
}
public function setZDepth(zDepth: Number): void
{
if(zDepth < MIN_Z)
zDepth = MIN_Z;
else if(zDepth > MAX_Z)
zDepth = MAX_Z;
if (advancedLayersEnabled(parent))
this["layerDepth"] = zDepth;
stage.invalidate();
}
public function getZDepth(): Number
{
if (advancedLayersEnabled(parent))
return this["layerDepth"];
else
return 0;
}
public function resetZDepth()
{
setZDepth(0);
}
public override function set z(zDepth:Number): void
{
this["layerDepth"] = zDepth;
}
public override function get z():Number
{
return this["layerDepth"];
}
public function pinCameraToObject(guide:DisplayObject, dx:Number = 0, dy:Number = 0, dz:Number = 0)
{
cameraGuide.AttachGuide(guide, dx, dy, dz);
handlepinCameraToObject();
stage.invalidate();
}
public function setPinOffset(dx:Number, dy:Number, dz:Number)
{
cameraGuide.ChangeDelta(dx, dy, dz);
handlepinCameraToObject();
stage.invalidate();
}
public function unpinCamera()
{
cameraGuide.DetachGuide();
}
public function setCameraMask(maskObj:DisplayObject)
{
parent.mask = maskObj;
if(maskObj != null)
{
maskObj.visible = false;
if(advancedLayersEnabled(parent))
{
maskObj['isAttachedToCamera'] = true;
if(maskObj.parent != null)
maskObj.parent.removeChild(maskObj);
this.parent.addChild(maskObj);
}
else
handleCameraMask();
}
}
public function removeCameraMask()
{
parent.mask = null;
}
private function getMatrix2DFrom3D(mat3D:Matrix3D): Matrix
{
var rawMatrixData:Vector.<Number> = mat3D.rawData;
var mat:Matrix = new Matrix();
mat.a = rawMatrixData[0];
mat.b = rawMatrixData[1];
mat.tx = rawMatrixData [12];
mat.c = rawMatrixData[4];
mat.d = rawMatrixData[5];
mat.ty = rawMatrixData[13];
return mat;
}
public function getCameraMatrix(): Matrix
{
handlepinCameraToObject();
var mat:Matrix;
if(this.transform.matrix3D)
{
mat = getMatrix2DFrom3D(this.transform.matrix3D);
}
else
{
mat = this.transform.matrix;
}
if (mat != null)
{
mat.invert();
mat.translate(centerX, centerY);
}
return mat;
}
private function cameraEnterFrame(...evt):void
{
handlepinCameraToObject();
if(!advancedLayersEnabled(parent))
handleCameraMask();
}
private function handlepinCameraToObject():void
{
if(cameraGuide.IsAttachedToGuide())
{
var attachPoint = cameraGuide.GetAttachmentPoint();
this.x = attachPoint.x;
this.y = attachPoint.y;
if(advancedLayersEnabled(parent))
this["layerDepth"] = attachPoint.z;
}
}
private function handleCameraMask():void
{
if(parent != null && parent.mask != null)
{
parent.mask.x = this.x;
parent.mask.y = this.y;
}
}
private function cameraControl(...event): void
{
if(!parent)
return;
checkForAdvancedLayerEnabled(parent);
var mat: Matrix = this.transform.matrix;
if (mat != null && !advancedLayersEnabled(parent))
{
mat.invert();
mat.translate(centerX, centerY);
parent.transform.matrix = mat;
parent.filters = this.filters;
parent.transform.colorTransform = this.transform.colorTransform;
}
}
private function resetStage(e: Event): void
{
removeEventListener(Event.ENTER_FRAME, cameraEnterFrame);
removeEventListener(Event.FRAME_CONSTRUCTED, cameraControl);
removeEventListener(Event.REMOVED_FROM_STAGE, resetStage);
parent.scaleX = 1;
parent.scaleY = 1;
parent.x = 0;
parent.y = 0;
if (transform.matrix3D) {
parent.scaleZ = 1;
parent.z = 0;
parent.rotationX = 0;
parent.rotationY = 0;
parent.rotationZ = 0;
}
else {
parent.rotation = 0;
}
parent.visible = true;
parent.filters = [];
if(parent.transform)
parent.transform.colorTransform = new ColorTransform();
}
private function checkForAdvancedLayerEnabled(parentContainer:DisplayObjectContainer)
{
/*for(var i=0; i<parentContainer.numChildren; i++)
{
var dispObj = parentContainer.getChildAt(i);
if(dispObj.hasOwnProperty('containerType') && (dispObj['containerType'] == 1 || dispObj['containerType'] == 2) )
{
parent['___layerDepthEnabled___'] = true;
return;
}
}
parent['___layerDepthEnabled___'] = false;*/
}
private function advancedLayersEnabled(parentContainer:DisplayObjectContainer):Boolean
{
return true;
//return parent['___layerDepthEnabled___'];
}
}
}
