我的代码有效,但它没有在最后一个函数中获取VAR。我错过了什么?
主类代码
package {
import flash.display.MovieClip;
import flash.events.*;
import com.Bubble;
public class numberPop extends MovieClip
{
public var numberBubble:Bubble;
public function numberPop()
{
addBubble(3);
}
public function addBubble(num:Number)
{
var i:Number = num;
numberBubble = new Bubble(i);
addChild(numberBubble);
}
}
}
第二类代码:Bubbles.as
package com {
import flash.display.MovieClip;
import flash.events.*;
public class Bubble extends MovieClip
{
public var num:Number;
public function Bubble(num:Number)
{
super();
num = num;
trace("Number is: " + num); /// WORKS !!!!!
this.addEventListener(MouseEvent.CLICK, bubbleAction);
}
public function bubbleAction(e:Event)
{
trace(num); // DOES NOT WORK BUT SHOULD.
}
}
}
答案 0 :(得分:1)
构造函数中的参数覆盖了类属性。变化:
num = num;
到
this.num = num;