我一直在研究AS3项目,但由于我通常使用php / javascript,这种语言对我来说是新的,我遇到了一个问题,我无法弄清楚如何解决。我以为我在这里问它,因为它可能非常简单,我只是错过了一些(真的)基本的东西。
这是我的外部AS3文件中的代码:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Shape;
import flash.display.Graphics;
public class lightstage_debug extends MovieClip {
//create drag functions for tools
public function dragMirror1(event:MouseEvent):void
{
if (stage.contains(mirror1))
{
mirror1.startDrag();
}
}
public function releaseMirror1(event:MouseEvent):void
{
if (stage.contains(mirror1))
{
mirror1.stopDrag();
}
}
/*********************************************************************************************
TODO: make mirror2, mirror3 etc drag function exist in code even when those mirrors don't exist
**********************************************************************************************/
public function reCheck(event:Event):void
{
//BEGIN LEVEL 1 RECHECK//
if (level.number == 1)
{
//check if mirror1 is touching line1
if (mirror1.hitTestObject(line1))
{
//redraw line 1 to stop at mirror1
/*************************************************************************************
TODO: MAKE LINE1 END **EXACTLY** WHERE MIRROR1 TOUCHES IT
**************************************************************************************/
line1.graphics.clear();
line1.graphics.lineStyle(2,0x000000,1);
line1.graphics.moveTo(0,200);
line1.graphics.lineTo((mirror1.x + (mirror1.width/2)),200);
//redraw line 2 to start at mirror1
line2.graphics.clear();
line2.graphics.lineStyle(2,0x000000,1);
line2.graphics.moveTo((mirror1.x + (mirror1.width/2)),200);
line2.graphics.lineTo(0,200);
lines.addChild(line2);
//show line2
//line2.visible = true;
//line2.alpha = 100;
trace('line didnt appear');
}
//run this if line1 is not touching mirror1
else
{
//redraw line 1 to reach the end of the stage
line1.graphics.clear();
line1.graphics.lineStyle(2,0x000000,1);
line1.graphics.moveTo(0,200);
line1.graphics.lineTo(550,200);
//hide line2
//line2.alpha = 0;
}
}
//END LEVEL 1 RECHECK//
}
}
}
以下是我的.FLA文件中的代码:
//import libraries
import flash.display.Shape;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Graphics;
//create variables
var globe1:MovieClip = new globe;
var mirror1:MovieClip = new mirror;
//create display containers
var lines:MovieClip = new MovieClip;
var mirrors:MovieClip = new MovieClip;
var concaves:MovieClip = new MovieClip;
var convexes:MovieClip = new MovieClip;
var globes:MovieClip = new MovieClip;
//create shapes for this level
var line1:Shape = new Shape;
var line2:Shape = new Shape;
//add display containers to the stage
addChild(lines);
addChild(mirrors);
addChild(concaves);
addChild(convexes);
addChild(globes);
//create level object to store level properties
var level:Object = new Object;
//create scene properties
level.mirrors = 1;
level.concaves = 0;
level.convexes = 0;
level.globes = 1;
level.number = 1;
//add all lines to the stage
lines.addChild(line1);
lines.addChild(line2);
//draw line1
line1.graphics.clear();
line1.graphics.lineStyle(2, 0x000000, 1);
line1.graphics.moveTo(0,200);
line1.graphics.lineTo(550, 200);
//4DEBUG: testing to see why line2 dosent appear
line2.graphics.clear();
//add mirrors
mirrors.addChild(mirror1);
//add concaves
//add convexes
//add globes
globes.addChild(globe1);
//position mirrors
mirror1.x = 340;
mirror1.y = 300;
//position globes
globe1.x = 125;
globe1.y = 50;
//create listeners
mirror1.addEventListener(MouseEvent.MOUSE_DOWN, dragMirror1);
mirror1.addEventListener(MouseEvent.MOUSE_UP, releaseMirror1);
stage.addEventListener(Event.ENTER_FRAME, reCheck);
我的舞台是空的,此刻我只有一帧。 globe和mirror动画片段在我的库中,带有我用来在代码中创建它们的AS3链接名称。
我试图创建类似于http://raphaelhennessy.com/misc/Explanation.png所描述的内容(忽略文本下面的所有内容' LightStage说明') - 但我的问题是虽然我可以获得初始行( line1)到'收缩'当镜子放在线的顶部时停在镜子上,第2行不会出现并从镜子开始,按照预期向上移动到舞台的顶部。
提前致谢,
-Raph
答案 0 :(得分:0)
您希望line2.graphics.lineTo(0,200);
成为line2.graphics.lineTo((mirror1.x + (mirror1.width/2)), 0);
。现在你只是在相反的方向上绘制线条。