Copy link to clipboard
Copied
Hello everyone !
I run into this problem today ... take a look on the code :
import com.trick7.effects.TeraFire;
for (var j:uint=0; j<10; j++) {
var fire:TeraFire = new TeraFire();
fire.x = j * 40 + 20;
fire.y = 100;
fire.number = j; //This line is causeing the problem
addChild(fire);
fire.buttonMode = true;
}
TeraFire class creates fire particles. The compiler error is :
Scene 1, Layer 'Layer 1', Frame 1, Line 7 1119: Access of possibly undefined property number through a reference with static type com.trick7.effects:TeraFire.
Anyone can help me to find a solution to this problem.
I can do that ".number" with a movieclip but not in this case. What can I do ?
Oops sorry typo... I meant to say fire["number"] = j;
Also the class needs to be dynamic for this to work, i.e.:
public dynamic class TeraFire extends MovieClip
(extending a dynamic class does not make the sub class dynamic...)
--
Kenneth Kawamoto
Copy link to clipboard
Copied
It means your TeraFire class has no public property "number" or public setter method. MovieClip is a dynamic class so that you can set non-existence property, and that's why you do not get the error if you use MovieClip. Either create the property in the class or make the class dynamic (by make it extends MovieClip or otherwise.)
--
Kenneth Kawamoto
Copy link to clipboard
Copied
I borrowed that class from the internet.
I made the changes you suggested: imported flash.Display.MovieClip and also made the class extend MovieClip.
The error is still throwing in compiler errors. I am not really good enough to edit this class because there are some functions I don't still understand very good. This is the class below:
package com.trick7.effects{
import flash.display.BitmapData;
import flash.display.GradientType;
import flash.display.MovieClip;
import flash.events.Event;
import flash.filters.DisplacementMapFilter;
import flash.filters.DisplacementMapFilterMode;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
public class TeraFire extends MovieClip{
public var phaseRateX:Number;
public var phaseRateY:Number;
private var offsets:Array= [new Point(),new Point()];
private var seed:Number = Math.random();
private var fireW:Number;
private var fireH:Number;
//火の色
//private var fireColorIn:uint;
//private var fireColorOut:uint;
private var ball:Sprite;
private var gradientImage:BitmapData;
private var displaceImage:BitmapData;
private var focalPointRatio:Number = 0.6;
private const margin:int = 10;
private var rdm:Number;
public function TeraFire(xPos:Number=0, yPos:Number=0, fireWidth:Number=30, fireHeight:Number=90, fireColorIn:uint = 0xFFCC00,fireColorOut:uint = 0xE22D09){
fireW = fireWidth;
fireH = fireHeight;
phaseRateX = 0;
phaseRateY = 5;
var matrix:Matrix = new Matrix();
matrix.createGradientBox(fireW,fireH,Math.PI/2,-fireW/2,-fireH*(focalPointRatio+1)/2);
var colors:Array = [fireColorIn, fireColorOut, fireColorOut];
var alphas:Array = [1,1,0];
var ratios:Array = [30, 100, 220];
var home:Sprite = new Sprite();
ball = new Sprite();
ball.graphics.beginGradientFill(GradientType.RADIAL,colors, alphas, ratios, matrix,"pad","rgb",focalPointRatio);
ball.graphics.drawEllipse(-fireW/2,-fireH*(focalPointRatio+1)/2,fireW,fireH);
ball.graphics.endFill();
//余白確保用透明矩形
ball.graphics.beginFill(0x000000,0);
ball.graphics.drawRect(-fireW/2,0,fireW+margin,1);
ball.graphics.endFill();
addChild(home);
home.addChild(ball);
this.x = xPos;
this.y = yPos;
addEventListener(Event.ENTER_FRAME,loop);
displaceImage = new BitmapData(fireW+margin,fireH,false,0xFFFFFFFF);
var matrix2:Matrix = new Matrix();
matrix2.createGradientBox(fireW+margin,fireH,Math.PI/2,0,0);
var gradient_mc:Sprite = new Sprite;
gradient_mc.graphics.beginGradientFill(GradientType.LINEAR,[0x666666,0x666666], [0,1], [120,220], matrix2);
gradient_mc.graphics.drawRect(0,0,fireW+margin,fireH);//drawのターゲットなので生成位置にこだわる必要はない。
gradient_mc.graphics.endFill();
gradientImage = new BitmapData(fireW+margin,fireH,true,0x00FFFFFF);
gradientImage.draw(gradient_mc);//gradient_mcを消す必要は?
rdm = Math.floor(Math.random()*10);
}
private function loop(e:Event):void{
for(var i:int = 0; i < 2; ++i){
offsets.x += phaseRateX;
offsets.y += phaseRateY;
}
displaceImage.perlinNoise(30+rdm, 60+rdm, 2, seed, false, false, 7, true, offsets);
displaceImage.copyPixels(gradientImage,gradientImage.rect,new Point(),null, null, true);
var dMap:DisplacementMapFilter = new DisplacementMapFilter(displaceImage, new Point(), 1, 1, 20, 10, DisplacementMapFilterMode.CLAMP);
ball.filters = [dMap];
}
}
}
I you can clarify a little bit further I would appreciate it a lot because I wasted some good time on this.
Copy link to clipboard
Copied
If you do fire[number] = j the error should go away (sorry I haven't got a time to test your class right now.)
But a better way is to create a public property in the class:
public var number:uint;
...or setter (and getter)
--
Kenneth Kawamoto
Copy link to clipboard
Copied
It didn't work neither this way.
Maybe I'll try later your suggestion. Anyway thanks for anything.
Copy link to clipboard
Copied
Oops sorry typo... I meant to say fire["number"] = j;
Also the class needs to be dynamic for this to work, i.e.:
public dynamic class TeraFire extends MovieClip
(extending a dynamic class does not make the sub class dynamic...)
--
Kenneth Kawamoto
Copy link to clipboard
Copied
Thank you so much.