Pulling my hair out here trying to solve this one. I have no experience with classes...I code everybit of AS3 into the frames usually. I was trying a custom class out and it just isn't working well.
I have a movieclip called mc_info_panel that I have placed onto my stage in frame one of my main timeline. One frame one of mc_info_panel i have the following AS3 code: stop(); on frame 2 of mc_info_panel I am trying to import my custom class:
import com.displayObj.ImgViewer;
Here are my errors codes:
//-----first error code----- 1046: Type was not found or was not a compile-time constant:ImageContainer. this error's location & source: Symbol 'mc_info_panel', Layer 'Layer 2', Frame 2, Line 35 var imageContainer:ImageContainer; //-----second error code----- 1046: Type was not found or was not a compile-time constant:ImageContainer. this error's location & source: Symbol 'mc_info_panel', Layer 'Layer 2', Frame 2, Line 287 var imgContainer:ImageContainer=new ImageContainer(); //-----third error code----- 1180: Call to a possibly undefined method ImageContainer. this error's location & source: Symbol 'mc_info_panel', Layer 'Layer 2', Frame 2, Line 287 var imgContainer:ImageContainer=new ImageContainer();
Why are these errors coming up?
Here is the class:
package com.displayObj
{
import flash.events.*;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.*;
import flash.geom.*;
//class to display a bitmap data with reflexion
public class ImageContainer extends MovieClip {
//bitmap object
private var bmp:Bitmap;
//reflection bitmap object
private var reflexion:Bitmap;
//ref bitmap data
private var refData:BitmapData;
//reflextion mask
private var refmask:Sprite;
public function ImageContainer() {
//initialize the bmp and the reflexion object
bmp=new Bitmap();
reflexion=new Bitmap();
//and add it to the image container
this.addChild(bmp);
}
//setter for the bitmap data
public function set imageData(value:BitmapData) {
//if the old value is not null dispose the data
if (bmp.bitmapData!=null) {
bmp.bitmapData.dispose();
}
//set the new data
bmp.bitmapData=value;
//update the position
reflexion.x=bmp.x=-bmp.width/2;
bmp.y=-bmp.height/2;
//flip the reflexion object
reflexion.scaleY=-1;
//force the smoothing
bmp.smoothing=true;
//create the reflextion bitmap data
refData=new BitmapData(bmp.width,bmp.height/4);
//and copy the pixel for the bmp bitmapdata
refData.copyPixels(bmp.bitmapData,new Rectangle(0,3*bmp.height/4,bmp.width,bmp.height/4),new Point(0,0));
//set the bitmap objects bitmap data
reflexion.bitmapData=refData;
//set the smoothing to true
reflexion.smoothing=true;
//update the reflextion position
reflexion.y=bmp.height/2+reflexion.height+5;
//create the mask
refmask=new Sprite();
//fill it with a gradient color (see help files)
var fillType:String = GradientType.LINEAR;
var colors:Array = [0xFFFFFF, 0xFFFFFF];
var alphas:Array = [0.5, 0];
var ratios:Array = [0x00, 0xFF];
var matr:Matrix = new Matrix();
matr.createGradientBox(reflexion.width, reflexion.height, Math.PI/2, 0, 0);
var spreadMethod:String = SpreadMethod.PAD;
refmask.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);
refmask.graphics.drawRect(0,0,reflexion.width, reflexion.height);
//see help files
//update the ref mask postion
refmask.x=reflexion.x;
refmask.y=reflexion.y-reflexion.height;
//cash as bitmap both the relexion mask and reflexion sprite
refmask.cacheAsBitmap=true;
reflexion.cacheAsBitmap=true;
//set the mask on the reflextion
reflexion.mask=refmask;
//add the mask
addChild(refmask);
this.scaleX=1;
this.scaleY=1;
//add reflexion
addChild(reflexion);
}
}