Flash AS3画线显示文字

Flash AS3 drawline displays text

我目前正在研究列线图,我能够创建 2 个与一条线相连的滑块,但是有没有办法让这条线读取中间的数字,就像下面的例子一样。

我需要一行来显示 "Distance" 的多个数字。

也可以让滑块以不同的度量单位显示多个数字,例如 meters/feet

选项 2

是否可以让 line.graphic 播放影片剪辑或按钮每次经过它时夸大其词?

到目前为止,我正在考虑使用一种敌人 class,所以每当 line.graphic 通过它时,它都会显示数字。

example nomograph

这是我目前所拥有的...对于滑块,我将一个动画片段 "imageholder1" 放在另一个动画片段的顶部 "rect"

var imgWidth:Number = imageHolder1.width;
var imgHeight:Number = imageHolder1.height;
var rectWidth:Number = rect.width;
var rectHeight:Number = rect.height;
var rectX:Number = rect.x;
var rectY:Number = rect.y;
var img1Width:Number = imageHolder2.width;
var img1Height:Number = imageHolder2.height;
var rect1Width:Number = rect1.width;
var rect1Height:Number = rect1.height;
var rect1X:Number = rect1.x;
var rect1Y:Number = rect1.y;
// Do math to correctly make the drag bounds using values attained above
var boundWidth = rectWidth - imgWidth;
var boundHeight = rectHeight - imgHeight;
var bound1Width = rect1Width - img1Width;
var bound1Height = rect1Height - img1Height;

var line:MovieClip = new MovieClip();
addChild(line);

draw(null);

imageHolder1.width = txtout.width
imageHolder1.minimum = 0;
imageHolder1.maximum = 100;
imageHolder1.value = 100;
imageHolder1.snapInterval = 2;

var sliderValues:uint = imageHolder1.y;
imageHolder1.addEventListener(Event.CHANGE, sliderChanged);
function sliderChanged(evt:Event):void {
sliderValues = imageHolder1.value/100;
txtout.text = (imageHolder1.value/100).toFixed(2);
}
// Now apply the variable numbers with the math we want as bounds
var boundsRect:Rectangle = new Rectangle(rectX, rectY, 
boundWidth, boundHeight);
    // Enable drag
    imageHolder1.addEventListener(MouseEvent.MOUSE_DOWN, DragImage1);
    function DragImage1(event:MouseEvent) {
// Here you see we apply the boundsRect when they drag
imageHolder1.startDrag(false, boundsRect);
 stage.addEventListener(Event.ENTER_FRAME, draw);
}
// Stop drag
imageHolder1.addEventListener(MouseEvent.MOUSE_UP, DropImage1);
function DropImage1(event:MouseEvent) {
imageHolder1.stopDrag();
 stage.addEventListener(Event.ENTER_FRAME, draw);
}

 var bounds1Rect:Rectangle = new Rectangle(rect1X, rect1Y, 
bound1Width, bound1Height);
    // Enable drag
    imageHolder2.addEventListener(MouseEvent.MOUSE_DOWN, DragImage2);
    function DragImage2(event:MouseEvent) {
    // Here you see we apply the boundsRect when they drag
imageHolder2.startDrag(false, bounds1Rect);
     stage.addEventListener(Event.ENTER_FRAME, draw);
}
// Stop drag
imageHolder2.addEventListener(MouseEvent.MOUSE_UP, DropImage2);
function DropImage2(event:MouseEvent) {
    imageHolder2.stopDrag();
     stage.addEventListener(Event.ENTER_FRAME, draw);
}

function draw(event:Event):void{
    line.graphics.clear();
    line.graphics.lineStyle(1,1);
    line.graphics.moveTo(imageHolder1.x,imageHolder1.y);
    line.graphics.lineTo(imageHolder2.x,imageHolder2.y);
}

var sliderValue:uint = imageHolder2.y;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
    sliderValue = imageHolder2.y;
    status_txt.text = "Slider position is: "+sliderValue;
}

更新

所以遇到了这个,我正在编辑它以满足我的需要,我能够在 flash 中跟踪所有信息,并了解更多关于 xml 到 flash 的信息。

但我现在的问题是如何将其全部实现到flash阶段?

 <?xml version="1.0" encoding="utf-8"?>

<flow>
    <axis name="diameter" type="parallel" 
    scaleFunction="log(t)"> 
    <range>0.01,02, ,50</range> 
    <xposition>0.0</xposition> 
    <crop>0.032,0.977</crop> 
    <title>Diameter [in.]</title> 
    </axis>
    <axis name="weightFlow" type="parallel" 
    scaleFunction="log(t)"> 
    <range>0.001,100000</range> 
    <xposition>0.16</xposition> 
    <crop>0.127,0.941</crop> 
    <title>Weight Flow [1000 
    lb./hr.]</title> 
    </axis> 
    <axis name="massVelocity" 
    type="parallel" scaleFunction="log(t)"> 
    <range>1.0,10000</range> 
    <xposition>0.325</xposition> 
    <crop>0.091,0.91</crop> 
    <title>Mass Velocity 
    [lb./(hr.)(sq.ft.)]</title> 
    </axis> 
    <axis name="turning" type="turning"> 
    <xposition>0.48</xposition> 
    </axis> 
    <axis name="pressureDrop" 
    type="parallel" scaleFunction="log(t)"> 
    <range>0.000001,100</range> 
    <xposition>0.713</xposition> 
    <crop>0.175,0.902</crop> 
    <title>Pressure Drop 
    [lb./sq.in./ft.pipe]</title> 
    </axis> 
    <axis name="pressure" type="parallel" 
    scaleFunction="log(t)" layout="left"> 
    <range>0.001,100</range> 
    <xposition>1.0</xposition> 
    <title>Centipoises^0.16/(lb./cu.ft. 
    at 1 atm)</title> 
    </axis>
</flow>

此代码将向您展示如何根据 "Rate" 和 "Velocity" 的指定数字计算 "Bore size"(中间值)。您可以更改 inputNum_RateinputNum_Velo。例如,在诺模图 image 中,您可以看到它们的 flow-rate 为 100 litres/min 和 4.5 metres/sec 的速度。中间值应该在 22 毫米左右(或 0.85 到 0.89 英寸?)。尝试这两个公式来确定您认为哪个更适合您的项目。

行业标准公式很简单:

D = Q / V (where D = diameter, Q = flow rate and V = velocity).

然而,为了与您的列线图图像紧密匹配,其他公式似乎效果更好:

Q = input_FlowRate x offset_of_Rate;
V = input_Velocity x offset_of_Velocity;
result = Q / V;
result = Math.sqrt(4 * result / Math.PI);
result *= 10; //# multiply by 10 for millimetres

Demo - 通过代码测试数字:
启动一个新项目并将代码粘贴到 Actions 面板,然后按 ctrl+enter 进行调试。
结果显示在调试器中(如果您没有看到文本/反馈/输出,请尝试按 F2)。

在代码部分“TEST APP”...转到步骤 (2) 并更改 inputNum_Rate = 100;inputNum_Velo = 4.5; 到您想要的任何单位(列在您的诺模图上)。

//# for: Define INPUT unit
var inputNum_Rate : Number = 0;     
var inputNum_Velo : Number = 0;

//# for: Define INPUT unit type (format)
var format_Rate : String = "ltr_pMin"; //set: "ltr_pMin" (Litres)or "gal_pMin" (Gallons)
var format_Diam : String = "mm"; //set: "mm" or "inches"
var format_Velo : String = "m_pSec"; //set: "m_pSec" (meters) or "ft_pSec" (feet)

var offset_Rate : Number = 16.66666666666666666; //Litres per Min
var offset_Velo : Number = 100.0; //Metres per Sec

var nvel : Number = 0;  var svel : Number = 0;
var nflow : Number = 0; var sflow : Number = 0;

var s : Number = 0;
var resultNum  : Number = 0; // holds the result

////////////// TEST APP /////////////////

//# 1) setup INPUT TYPE
format_Rate = "ltr_pMin"; //# Rate //set: "ltr_pMin" (Litres)or "gal_pMin" (Gallons)
format_Diam = "mm"; //# Diameter //set: "mm" or "inches"
format_Velo = "m_pSec"; //# Velocity //set: "m_pSec" (meters) or "ft_pSec" (feet)

//# 2) setup INPUT values ("Rate" & "Velocity" to get middle "Diameter");
inputNum_Rate = 100; inputNum_Velo = 4.5; //# These should be from input textbox

//# 3) calculate Diameter based on inputs of Rate & Velocity
resultNum = calculate_Diameter( inputNum_Rate, inputNum_Velo );
trace ("final :: resultNum : " + resultNum );

function calculate_Diameter( myRate:Number, myVelo:Number ) : Number
{
    //# RESET
    svel = nvel = nflow = sflow = s = resultNum = 0; //reset

    sflow = myRate * offset_Rate;
    svel = myVelo * offset_Velo;
    s = sflow/svel; //get Area
    s = Math.sqrt(4 * s / Math.PI);

    //# CONVERT
    s = s * 10;     s = Number(s.toPrecision(5));

    //# CHECK RESULTS IN DEBUGGER....
    trace("===========================================" );
    trace("\n FLOW RATE : " );
    //convert Litres and US gallons :: US-Gallons = ( litres / 3.79) || Litres = (3.79 * US-Gallons)
    trace("litres p/sec : " + ( myRate ) );
    trace("gallon p/sec : " + ( myRate / 3.79 ) );

    trace("\n BORE SIZE : " );
    //convert Mm and Inches :: (1 mm = 0.0393701 inch || 1 inch = 25.4 mm)
    trace("millms : " + (s) );
    trace("inches : " + (s * 0.0393701) );

    trace("\n VELOCITY : " );
    //convert Metres and Feet :: (1 metre= 3.28084 foot || 1 foot= 0.3048 metres)
    trace("m/sec  : " + ( myVelo ) );
    trace("ft/sec : " + ( myVelo * 3.28084 ) );
    trace("===========================================" );


    //# RETURN result of this function
    return resultNum;

}