把头发拉出来试图解决这个问题。我没有类的经验......我通常将AS3的每个位编码到帧中。我正在尝试一个自定义课程,但它运作不佳。
我有一个名为mc_info_panel的动画片段,我已将其放置在我的主要时间轴第一帧的舞台上。 mc_info_panel中的一个帧我有以下AS3代码:stop();在mc_info_panel的第2帧上我试图导入我的自定义类:
import com.displayObj.ImgViewer;
以下是我的错误代码:
//-----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();
为什么会出现这些错误?
这是班级:
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);
}
}
答案 0 :(得分:1)
AS4 Flash Importing Custom Classes
解决方案:重命名该类以反映文件的名称:ImageContainer.as而不是ImgViewer.as