mercredi 26 avril 2017

What's the AS3 equivalent of the following AS2 code?

I'm trying to translate the following AS2 code into AS3 because I have Adobe Flash CC, which doesn't, as far as I know (from research, trial and error), support AS2 code. Any help would be greatly appreciated...

onClipEvent(load) {
speed = 0;
acceleration = 0.4;
speedDecay = 0.96;
maxSpeed = 10;
backSpeed = 1;
}

onClipEvent(enterFrame) {
    if(Math.abs(speed) > 0.3) { 
        speed *= speedDecay;
    }else {
        speed = 0;
    }
    if(Key.isDown(Key.UP)) {
        if (Math.abs(speed) >= maxspeed) {
            speed += acceleration;
            }
        }
    if(Key.isDown(Key.DOWN)) {
        if(speed < 0.5) 
        speed = -2;
        else
        speed--;
    }
        if (Math.abs(speed)> 0.5) {
        if (Key.isDown(Key.LEFT)) {
            _rotation -= 10;
         }
         if (Key.isDown(Key.RIGHT)) {
            _rotation += 10;
            }
        }
       x = Math.sin(_rotation*(Math.PI/180))*speed;
       y = Math.cos(_rotation*(Math.PI/180))*speed*-1;

       if (!_root.ground.hitTest(_x+x, _y+y, true)) {
       _x += x;
       _y += y;
       }else {
        speed -= speed*1.5;   
       }
}

This code goes in the Car layer of my car game.

How can I make a symbol visible only if other two symbols are visible in ActionScript 3.0?

I want to make a symbol visible (symbol3) only if symbol1 and symbol2 are visible in ActionScript 3.0 (Adobe Animate CC), but I can't make it, because I am really new in programming... Can anyone help me?

Thanks a lot,

Tom

Actionscript: How do I scale this tree so it looks like it's growing

I am trying to set up an animation of a randomly generated tree, growing from a small sapling to a huge tree. I am able to randomly generate the tree, but when I try to scale it up/down, the tree moves left and right and stuff. I need it to stay in the same place when scaling it, and the tree changes position every time I play the flash

package
{
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;

public class Main extends Sprite 
{
    public var Tree:Sprite = new Sprite();
    public var obj:Sprite = new Sprite();
    private var s:Shape = new Shape(); 
    private const TrunkWidth:Number = 50, BranchEnd:Number = 10;

    public function Main() 
    {
        growTree(800 / 2, 600 / 2, 3, 2);

        stage.addEventListener(MouseEvent.CLICK, scaleUp);
    }

    public function scaleUp(e:MouseEvent)
    {
        Tree.scaleX = Tree.scaleX + 0.05;
        Tree.scaleY = Tree.scaleY + 0.05;
    }

    public function growTree(positionX:Number, positionY:Number, generations:Number, children:Number):void
    {
        var g:Graphics = s.graphics;
        var endPointY:Number = randomRange(positionY -170, positionY - 200);
        g.lineStyle(TrunkWidth, Math.random() * 0xFFFFFF);
        g.moveTo(positionX, positionY);
        g.lineTo(positionX, endPointY);
        obj.addChild(s);
        createBranch(positionX, endPointY, children, endPointY, generations, 1);
    }

    private function randomRange(minNum:Number, maxNum:Number):Number 
    {
        return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
    }

    private function createBranch(x:int, y:int, children:int, height:Number, totalGens:Number, currentGen:Number):void
    {
        var i:int;
        var temp_XPos:Number;
        var temp_YPos:Number;
        for (i = 0; i < children; i++)
                {
                    var temp_Shape:Shape = new Shape();
                    var g:Graphics = temp_Shape.graphics;
                    temp_XPos = randomRange( -100 + x, 100 + x);
                    temp_YPos = height - randomRange( 50, 100);
                    g.lineStyle((TrunkWidth - BranchEnd) / totalGens * (totalGens - currentGen) + BranchEnd, Math.random() * 0xFFFFFF);
                    g.moveTo(x, y);
                    g.lineTo(temp_XPos, temp_YPos);
                    obj.addChild(temp_Shape);
                    if (currentGen < totalGens)
                    {
                        createBranch(temp_XPos, temp_YPos, children, temp_YPos, totalGens, currentGen + 1)
                    }
                    else
                    {
                        obj.x = -obj.width;
                        obj.y = -obj.height;

                        Tree.addChild(obj);
                        Tree.y = 500;
                        Tree.x = 0;
                        addChildAt(Tree, 0);
                    }
                }
            }
        }

    }

How can I make a symbol appear after clicking in two different buttons in actionscript 3.0?

I am a little bit new in this programming stuff and I need help to program in ActionScript 3.0 (Adobe Animate CC). I want to make a symbol (graph) visible but only after clicking in two different buttons (button1 and button 2). I can make that with just one button, but I can't make it with two buttons... Can anyone help me?

Tom

How can I make something show after clicking in two different buttons in c#?

I am really new in programming and I need help to solve a little issue, please. I started programming in Adobe Animate CC (ActionScript 3.0) and I want to know how to make a symbol appear only after clicking in two buttons. I can do that with just one button, but I don't know how to make it with two buttons:

button.addEventListener (MouseEvent.CLICK, onClick)

function onClick (e:MouseEvent):void
 {
  graph.visible = true;
 }

Thanks,

João

mardi 25 avril 2017

Adobe AIR call SoftKeyboardType Phone IOS

is it possible to call phone (not number but phone) keyboard from adobe air on ipa IOS? or is there any ANE?

enter image description here

How to load a SharedObject from another Swf file in actionScript 3.0

This code works, but when I put the loadBtn and the function 'loadNames' in another swf file, the program traces this: "saved names: undefined", in addition I'd like to specify the path of the object saved:how can i do that?

var SO:SharedObject=SharedObject.getLocal("mySave");

var archive:Array=new Array(); var counter:Number=-1;

saveBtn.addEventListener(MouseEvent.CLICK, saveName); loadBtn.addEventListener(MouseEvent.CLICK, loadNames);

function saveName(event:Event) {

counter++;

archive[counter]=input.text;

SO.data.arrSaved=archive;

SO.flush();

}

function loadNames(event:Event) {

trace("saved names: "+SO.data.arrSaved);

}