Search code examples
actionscript-3flashformatactionscript-2

Convert AS2 Code to AS3 Format


please help me out converting the code below into as3. I have no ideea what is "SHEMA" , "BASE", "GLANCE" etc for AS3. THanks a lot. This code is being written inside a movie clip.

function CopyFromShema(sframe)
{
    SHEMA.gotoAndStop(sframe);
    GLANCE.filters = SHEMA.GLANCE.filters;
    BASE.filters = SHEMA.BASE.filters;
    CAPTION.filters = SHEMA.CAPTION.filters;
}
SHEMA._visible = false;
SHEMA.gotoAndStop(1);
BASE.scale9Grid = new flash.geom.Rectangle(10, 10, 100, 5);
GLANCE.scale9Grid = new flash.geom.Rectangle(10, 6, 100, 2);
onRollOver = function ()
{
    CopyFromShema(3);
}
;
onRollOut = function ()
{
    CopyFromShema(2);
}
;
onPress = function ()
{
    CopyFromShema(4);
}
;
onRelease = function ()
{
    CopyFromShema(3);
}
;
onDragOver = function ()
{
    onPress();
}
;
onDragOut = function ()
{
    onRollOut();
}
;

Solution

  • as pointed in line "3" of provided code in question, SHEMA.gotoAndStop(sframe); they are all MovieClips and not As2 Classes/Keywords.

    everything is ok in AS3 just replace (do it for all event fucntions)

    onRollOver = function ()
    {
        CopyFromShema(3);
    };
    

    with As3 Event handlers

    stage.addEventListener(MouseEvent.ROLL_OVER, function(e:MouseEvent):void {
        CopyFromShema(3);
    });
    

    about other MouseEvents :

    1. onRollOut : MouseEvent.ROLL_OUT
    2. onPress : MouseEvent.MOUSE_DOWN
    3. onRelease : MouseEvent.MOUSE_UP
    4. onDragOver : N/A (its MOUSE_OVER while MOUSE_DOWN)
    5. onDragOut : N/A (its MOUSE_OUT while MOUSE_DOWN)

    so what to do with non available events in as3? they are available but you have to handling them with bunch of available events, here is an example of it.


    [update] why chaning AS2 to AS3?

    most times, there is no real need for porting AS2 to AS3, but you can simply compile AS2 projects as swf, then embedding them in to the AS3 projects, and let them communicate with each other trough a LocalConnection as mentioned here