as3.0中鼠标隐藏后怎么把跟随的原件位于所有可视文件的上方?
这是主文件main函数代码的一部分:publicvarqiqiushu:qiqiu=newqiqiu();publicvarzhentous:zhentou=newzhe...
这是主文件main函数代码的一部分:
public var qiqiushu:qiqiu=new qiqiu();
public var zhentous:zhentou=new zhentou();
public var container:Sprite=new Sprite();
private var m:uint=0;
public function main() {
start_btn.addEventListener(MouseEvent.CLICK,start_click);
stage.addChildAt(zhentous,20);
}
public function start_click(e:MouseEvent):void{
for (var i:uint = 0; i<15; i++) {
qiqiushu=new qiqiu();
arrayqiqiu.push(qiqiushu);
container.addChild(arrayqiqiu[i]);
arrayqiqiu[i].x=Math.random()*300+100;
arrayqiqiu[i].y=Math.random()*400+100;
}
xianshi_text.visible=false
this.addChild(container);
this.addEventListener(Event.ENTER_FRAME,thiscqs_frame);
container.addEventListener(MouseEvent.CLICK,qiqiu1_click);
}
这是zhen.as中的代码:
package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class zhen extends MovieClip{
public function zhen(){
this.addEventListener(Event.ENTER_FRAME,this_zhenframe);
}
public function this_zhenframe(e:Event):void{
Mouse.hide();
this.x=root.mouseX+70;
this.y=root.mouseY+28;
}
}
}
会出现TypeError: Error #1009: 无法访问空对象引用的属性或方法。
at zhen/this_zhenframe()
求解答! 展开
public var qiqiushu:qiqiu=new qiqiu();
public var zhentous:zhentou=new zhentou();
public var container:Sprite=new Sprite();
private var m:uint=0;
public function main() {
start_btn.addEventListener(MouseEvent.CLICK,start_click);
stage.addChildAt(zhentous,20);
}
public function start_click(e:MouseEvent):void{
for (var i:uint = 0; i<15; i++) {
qiqiushu=new qiqiu();
arrayqiqiu.push(qiqiushu);
container.addChild(arrayqiqiu[i]);
arrayqiqiu[i].x=Math.random()*300+100;
arrayqiqiu[i].y=Math.random()*400+100;
}
xianshi_text.visible=false
this.addChild(container);
this.addEventListener(Event.ENTER_FRAME,thiscqs_frame);
container.addEventListener(MouseEvent.CLICK,qiqiu1_click);
}
这是zhen.as中的代码:
package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class zhen extends MovieClip{
public function zhen(){
this.addEventListener(Event.ENTER_FRAME,this_zhenframe);
}
public function this_zhenframe(e:Event):void{
Mouse.hide();
this.x=root.mouseX+70;
this.y=root.mouseY+28;
}
}
}
会出现TypeError: Error #1009: 无法访问空对象引用的属性或方法。
at zhen/this_zhenframe()
求解答! 展开
1个回答
展开全部
我找到你的问题所在了,出在了root上,root是主时间轴变量,它属于舞台容器中的实例。而你在外部类中调用,它不属于一个域的问题,所以你必须想办法为类Zhen提供一个root的接口,可以用参数的方法传递,比如你这样写类
package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class zhen extends MovieClip{
private var _root:MovieClip;
public function zhen(obj:MovieClip){
_root=obj;
this.addEventListener(Event.ENTER_FRAME,this_zhenframe);
}
public function this_zhenframe(e:Event):void{
Mouse.hide();
this.x=_root.mouseX+70;
this.y=_root.mouseY+28;
}
}
}
然后在实例化的时候这样写
var myRoot:Zhen=new Zheh(root);
就可以了。希望你成功。
package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class zhen extends MovieClip{
private var _root:MovieClip;
public function zhen(obj:MovieClip){
_root=obj;
this.addEventListener(Event.ENTER_FRAME,this_zhenframe);
}
public function this_zhenframe(e:Event):void{
Mouse.hide();
this.x=_root.mouseX+70;
this.y=_root.mouseY+28;
}
}
}
然后在实例化的时候这样写
var myRoot:Zhen=new Zheh(root);
就可以了。希望你成功。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询