This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-03-07 16:07:12

midnightleopard
Scratcher
Registered: 2007-09-13
Posts: 1000+

Porting into flash

DIscuss here how to translate scratch blocks into action script commands


http://pwp.wizards.com/5103673563/Scorecards/Landscape.png

Offline

 

#2 2010-03-07 17:49:49

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Porting into flash

I am condensing these into one post:
Format: block spec (argument name:actionScript argument type) block spec - actionScript;
I am using 'this' as the sprite in the actionScript
I apologize if I use nonexistent classes and properties. I have Flex Builder, not Flash, so I don't know if some of the classes I use are different.

----------
Motion
move (t1:Number) steps - this.x += t1 * Math.sin(this.rotation); this.y += t1 * Math.cos(this.rotation);
turn clockwise (t1:Number) degrees - this.rotation -= t1;
turn counterclockwise (t1:Number) degrees - this.rotation += t1;

point in direction (t1:Number) - this.rotation = t1;
point towards (t1:DisplayObject) - TBW*

go to x: (t1:Number) y: (t2:number) - this.x = t1; this.y = t2;
go to (t1:DisplayObject) - this.x = t1.x; this.y = t1.y;
glide (t1:Number) secs to x: (t2) y: (t3) - TBW*

change x by (t1:Number) - this.x += t1;
set x to (t1:Number) - this.x = t1;
change y by (t1:Number) - this.y = t1;
set y to (t1:Number) - this.y = t1;

if on edge, bounce - TBW*

x position - return this.x;
y position - return this.y;
direction - return this.rotation;

Looks
I used a little freedom here in assuming that the object has an arrayCollection called 'costumes' which contains classes with embedded sources. There is also a variable called costumeIndex which contains the current costume index.
switch to costume (t1) - TBW*
next costume - costumeIndex = (costumeIndex + 1) % costumes.length;

say (t1:String) for (t2:Number) secs - TBW*
say (t1:String) - TBW*
think (t1:String) for (t2:Number) secs - TBW*
think (t1:String) - TBW*

change (t1:String) effect by (t2:Number) - TBW*
set (t1:String) effect to (t2:Number) - TBW*
clear graphic effects - TBW*

change size by (t1:Number) - TBW*
set size to (t1:Number) - TBW*
size - TBW*

show - this.visible = true;
hide - this.visible = false;

go to front - TBW*
go back (t1:Number) layers - TBW*

Sound
These cannot really be accomplished in actionScript without a built-in library

Pen
TBW*

Control
When green flag clicked call function (t1:Function) - Application.application.addEventListener(FlexEvent.CREATION_COMPLETE, t1); only in Flex
When (t1:String) key pressed call function (t1:Function) - TBW*
When sprite clicked call function (t1:Function) - Application.application.addEventListener(MouseEvent.CLICK, t1);

wait (t1:Number) secs - TBW*

forever (t1:Function) - setInterval(t1, 1);
repeat (t1:Number) ... end - for (var i:Number = 0; i < t1; i++) { ... }

broadcast (t1:Function) - setTimeout(t1, 0);
broadcast (t1:Function) and wait - t1();

When I receive (t1:Function) - private function t1():int { ... return 0; }

forever (t1:Function) if (t2:Boolean) - setInterval(t1, 1); in t1: if (t2) { ... }
if (t1:Boolean) ... end - if (t2) { ... }
if (t1:Boolean) ... else ... end - if (t1) { ... } else { ... }
wait until (t1:Boolean) - while (!t1) { }
repeat until (t1:Boolean) ... end - while (!t1) { ... }

stop script - TBW*
stop all - TBW*

Sensing
touching (t1:DisplayObject) - return this.hitTest(t1);
touching color (t1:?) - TBW*
color (t1:?) is touching (t1:?) - TBW*

ask (t1:String) - TBW*
answer - TBW*

mouse x - return Application.application.mouseX;
mouse y - return Application.application.mouseY;


I will finish this soon.
----------
* TBW = To Be Written

Last edited by nXIII (2010-03-07 18:52:08)


nXIII

Offline

 

Board footer