2011-08-31 3 views
0

진자의 플래시 소스가 있습니다. Flex에서 사용하고 싶습니다. 소스 코드에서 이미지 (hand.png 및 pend.png)의 무비 클립 (ball0_mc 및 ball2_mc)을 대체합니다. 그러나 마지막 응용 프로그램에서 다른 종류의 물리 현상을 얻습니다. 움직임이 느려지고 로프가 이미지에서 벗어납니다.Flex 4.5에 AS2 코드 적용

누구든지이 특정 예에서 내가 잘못한 것을 조언 할 수 있습니까?

AS2 소스 : 플렉스에서

function lines(Void) 
{ 
    _root.createEmptyMovieClip("lines", _root.getNextHighestDepth()); 
    with (lines) 
    { 
     clear(); 
     lineStyle(1, 0); 
     _root.moveTo(ball0_mc._x, ball0_mc._y); 
     _root.lineTo(ball2_mc._x, ball2_mc._y); 
    } 
    return undefined; 
} 
function verlet(ball) 
{ 
    var __reg3 = ball.mc._x; 
    var __reg2 = ball.mc._y; 
    ball.mc._x = ball.mc._x + (ball.mc._x - ball.oldx); 
    ball.mc._y = ball.mc._y + (ball.mc._y - ball.oldy); 
    ball.mc._y = ball.mc._y + grav * dt * dt; 
    ball.oldx = __reg3 
    ball.oldy = __reg2 
} 
function constraints(ball0, ball1) 
{ 
    var __reg7 = new flash.geom.Point(ball0.mc._x, ball0.mc._y); 
    var __reg6 = new flash.geom.Point(ball1.mc._x, ball1.mc._y); 
    var __reg1 = __reg6.subtract(__reg7); 
    var __reg5 =Math.sqrt(__reg1.x * __reg1.x) + Math.sqrt(__reg1.y * __reg1.y); 
    var __reg4 = (__reg5 - restlength)/__reg5 * (ball0.mass * 1 + ball1.mass * 1); 
    ball0.mc._x = ball0.mc._x + ball0.mass * 1 * __reg1.x * __reg4; 
    ball0.mc._y = ball0.mc._y + ball0.mass * 1 * __reg1.y * __reg4; 
    ball1.mc._x = ball1.mc._x - ball1.mass * 1 * __reg1.x * __reg4; 
    ball1.mc._y = ball1.mc._y - ball1.mass * 1 * __reg1.y * __reg4; 
    return undefined; 
} 
var t = 0; 
var ct = 0; 
var dt = 0; 
var particles = new Array(); 
var ball = new Object(); 
ball.oldx = ball0_mc._x; 
ball.oldy = ball0_mc._y; 
ball.mc = ball0_mc; 
ball.mass = 0.2; 
particles.push(ball); 

var ball = new Object(); 
ball.oldx = ball2_mc._x; 
ball.oldy = ball2_mc._y; 
ball.mc = ball2_mc; 
ball.mass =0.2; 
particles.push(ball); 
var grav = 0.5; 
var restlength = 120; 
_root.onEnterFrame = function (Void) 
{ 
    ++t; 
    dt = t - ct; 
    ct = t; 
    var __reg1 = 1; 
    while (__reg1 < particles.length) 
    { 
     var __reg2 = particles[__reg1]; 
     verlet(__reg2); 
     ++__reg1; 
    } 
    constraints(particles[0], particles[1]); 
    particles[0].mc._x = _xmouse; 
    particles[0].mc._y = _ymouse; 
    lines(); 
    return undefined; 
} 
; 

결과 :

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    width="760" height="760" minWidth="760" minHeight="760" 
     creationComplete="application1_creationCompleteHandler(event)"> 

<fx:Script> 
<![CDATA[ 
    import mx.core.IVisualElement; 
    import mx.events.FlexEvent; 

    private var t = 0; 
    private var ct = 0; 
    private var dt = 0; 
    private var particles:Array = new Array(); 
    private var grav = 0.5; 
    private var restlength = 120; 
    private var mass = 0.2; 

    protected function application1_creationCompleteHandler(event:FlexEvent):void 
    { 
    rope.xFrom = hand.x+30; 
    rope.yFrom = hand.y+50; 
    rope.xTo = pend.x + 10; 
    rope.yTo = pend.y; 

    addEventListener(MouseEvent.MOUSE_MOVE, startDragging); 
    var ball = new Object(); 
    ball.oldx = hand.x; 
    ball.oldy = hand.y; 
    ball.mc = hand; 
    ball.mass = 0.2; 
    particles.push(ball); 

    var ball = new Object(); 
    ball.oldx = pend.x; 
    ball.oldy = pend.y; 
    ball.mc = pend; 
    ball.mass =0.2; 
    particles.push(ball); 

    //constraints(particles[1], particles[2]); 
    } 

    protected function verlet(ball):void 
    { 
    var __reg3 = ball.mc.x; 
    var __reg2 = ball.mc.y; 
    ball.mc.x = ball.mc.x + (ball.mc.x - ball.oldx); 
    ball.mc.y = ball.mc.y + (ball.mc.y - ball.oldy); 
    ball.mc.y = ball.mc.y + grav * dt * dt; 
    ball.oldx = __reg3 
    ball.oldy = __reg2 
    } 
    protected function constraints(ball0, ball1):void 
    { 
    var __reg7 = new flash.geom.Point(ball0.mc.x, ball0.mc.y); 
    var __reg6 = new flash.geom.Point(ball1.mc.x, ball1.mc.y); 
    var __reg1 = __reg6.subtract(__reg7); 
    var __reg5 =Math.sqrt(__reg1.x * __reg1.x) + Math.sqrt(__reg1.y * __reg1.y); 
    var __reg4 = (__reg5 - restlength)/__reg5 * (ball0.mass * 1 + ball1.mass * 1); 
    ball0.mc.x = ball0.mc.x + ball0.mass * 1 * __reg1.x * __reg4; 
    ball0.mc.y = ball0.mc.y + ball0.mass * 1 * __reg1.y * __reg4; 
    ball1.mc.x = ball1.mc.x - ball1.mass * 1 * __reg1.x * __reg4; 
    ball1.mc.y = ball1.mc.y - ball1.mass * 1 * __reg1.y * __reg4; 
    } 
    protected function startDragging(event:MouseEvent):void 
    { 
    hand.x = this.mouseX; 
    hand.y = this.mouseY; 
    rope.xFrom = hand.x+30; 
    rope.yFrom = hand.y+50; 
    rope.xTo = pend.x + 10; 
    rope.yTo = pend.y; 
    ++t; 
    dt = t - ct; 
    ct = t; 
    var __reg1 = 1; 
    while (__reg1 < particles.length) 
    { 
    var __reg2 = particles[__reg1]; 
    verlet(__reg2); 
    ++__reg1; 
    } 
    constraints(particles[0], particles[1]); 
    } 

]]> 
</fx:Script> 
<s:Line id="rope"> 
<s:stroke> 
    <s:SolidColorStroke color="black" weight="1.2"/> 
</s:stroke> 
</s:Line> 
<s:Image id="hand" x="365" y="76" smooth="true" source="@Embed('images/hand.png')"/> 
<s:Image id="pend" x="410" y="392" smooth="true" source="@Embed('images/pend.png')"/> 
</s:Application> 

답변

1

이 문제에 대한 대답은 각 AS2 기능과 2의 최종 목표 출력 무엇인지) 1을 이해할 필요가 있다는 것입니다) 얼마나 자주 해당 함수가 호출됩니다.

예를 들어 Flex 버전에서 onEnterFrame과 동일한 AS2 문제가 발생하지 않는 이유가 확실하지 않습니다. 또는 Flex 애플리케이션이 24fps로 실행되고 AS2 프로젝트 .fla가 다른 프레임 속도로 실행될 수 있습니다.

플렉스 버전에서는 AS2 버전에 드래그 한 비즈니스가 추가됩니다.

여기에 잘못하고있는 것들이 너무 많아서 각 기능의 목적을 이해할 필요가 있습니다.

AS2와 Flex 모두에서 경험이 있다면, 포트가 가능합니다 ... 예외적으로 Flex의 기본 프레임 속도 인 24fps보다 높게는 수행 할 수 없습니다. 프레임 높이를 높게 설정할 수는 있지만 Flex Framework가 원래 설계된 사양 및 매개 변수에서 벗어날 위험이 있습니다.

관련 문제