6/21/2008

Avoiding .sol hacking

Some of you may know (and may use) the famous 'Flash cookies'.
I'm talking about a Shared Object that is used by the developer to store data to the users' computers. It can be used to store a highscore, the last level and even password information.
You may think 'Why would somebody hack a .sol file?' well, nevermind, but people were thinking the same about hacking a .swf file.

Ok, I'll make a example:
On Kongregate, all game saves are made using Shared Objects.
Games use this method to store a highscore, a level score, the last level reached, the cash the player has and other stuff.
Now, with a simple program called SOL Editor I could easily hack a game save data and win a badge for it.
Now, if someone also had this brilliant idea, (s)he would hack it to.
It would be a catastrophe if everybody think the same thing.

How to solve this?
Well, unlike .swf, you cannot encrypt a .sol object via Flash, but you can use some nasty tricks to obfuscate the .sol object:

1: Using fake data:
Store a variable called 'MONEY' (yes, with caps) in the .sol object and give it a unique value.
like: 18948
In the .swf, load this value, and test if it still 18948. If not, someone hacked it! If someone did hacked it, just reset the data on it.

2: Using encrypted data:
In the case some smart user found that there's no money in your pinball game, you can use obfuscated data to avoid malicious changes.
Like:

currentl = "adskGrh";

As the variable shown up there does not follow a logic (not explicit), the user will not know what do do.

3: Using swapped vars:
As the name says, you just need to swap two variables values and save it.
Like:

score = 13245;
currLevel = 12;

Swapping on the SharedObject, it would sound like this:

score = 12;
currLevel = 13245

4: Using japanese chars to crash the editor:
the saved .sol!This is my favorite way to do the job, but I must warn you that doing this you run the risk of lose the .sol!
But anyway, it's as simple as 123:
Save the normal data, and when finished, save a random variable with a japanese/other strange language char:

貘 = 譞

When the editor try to load , it will crash.
But some .sol editors skip these vars.


Well, that's all for today! You can stude more using our favorite tutorial finder!

Bye!

6/11/2008

Making a Scroll Bar in Flash 8

Other day I was making a rate system for a site and then I faced with a BIG trouble: The scroll bars.

it took me 3 hours before figuring out how to do one and with help of a video tutorial!

So, as many of you who are reading this may be needing some help, I decided to make this small tutorial to teach you how to make a small Scroll bar with dynamic resizing ;)


Ok, so let's start with a 300x1000 MovieClip with a bunch of stuff in it (that forms a 300x1000 MC), rename it 'Content'.
Now, to start making the scrollbar, you need first mask the scrolling MC with a 300x300 shape.


Here I made this and I applied a drag system so you can see what I'm talking about:




You can see that the MC is being masked, but where's the scroll bar?
So we'll start by the slider:

create a MC with the same height of the mask and place it a little bit to the right of the scrolling MC. Just like this:



Convert it to a MovieClip and rename it 'slider'.
To make the thumb, just duplicate it and make it darker:


You can't really se the slider becouse the thumb is covering it, but even if the content is smaller than the masking area (therefore, the thumb is no needed) it (thumb) will be hidden.

Anyway, now whe REALLY need start scripting. Let's start by resizing the thumb:

resizeFactor = 100; // Resizing factor, the less this is, the smaller the thumnb will be.
thumb._yscale = (300/Content._height)*resizeFactor; // 300 of the masking shape's heigth
if(Content._heigth < 300) // Hide the thumb if the content is smaller than the visible area
thumb._visible = false;

Now, calculate tha max y position of the thumb for dragging intentions:

yMax = (slider._height-thumb._height);

The dragging, for me, is the hardest part. We'll have to figure out how to move the content MC the right amount as the thumb goes down.
And the best way to do this is using percentage calcules! :D
The idea is this:

thumb._y/yMax = percentage of scrolling.

So, if we do a little math...

Content._y = -(Content._heigth - maskHeigth)*(percentage of scrolling);

this will result in a nice, smooth scrolling system :D

but before!

The boooring dragging system:

drag = false;

// the resizing code goes here.

thumb.onPress = function(){
yOff = thumb._y - _ymouse;
drag = true;
}

thumb.onRelease = function(){
drag = false;
}

thumb.onReleaseOutside = function(){
drag = false;
}

thumb.onMouseMove = function(){
if(drag){
thumb._y = _ymouse+yOff;
}
//APPLY SCROLLING CODE HERE!
}


In the place of the APPLY SCROLLING CODE HERE! comment we'll put the scrolling code (duh!).

I'll save you're time an provide a ready-to-past code:

Content._y = (Content._height-300)*(thumb._y/yMax);

But wait! I forgot to script the bondaries code xD
This code goes right after the if(drag) code:

thumb._y = Math.max(thumb._y,0);
thumb._y = Math.min(thumb._y,yMax);

Putting togheter all this mess, converting it to a MC, applying a final 'touch', this is what we get:


http://www.swfme.com/view/1103912


And why not download the source!

Thanks for reading! Bye :)

6/08/2008

gotoAndLearn

I'm here to talk about a great Flash video tutorials site I found on my wandering around the internet. I'm talking about gotoAndLearn. You may think: "Oh yeah... Another paid site..."
But ALL tutorials are FREE and they come with source! :D

There are ActionScript 2 and 3 tutorials, and even 4 Astro tutorials!


It's great, worth to check out ;)

http://www.gotoandlearn.com

6/06/2008

FlashDevelop

No, I'm not talking about the blog, but the FlashDevelop, a software that I found on my wandering on LivesInABox's Adventures in Actionscript blog.

I think it's a great software with a really good potential, but before saying anything, why don't you try downloading it?


And for those who're wondering, it's an ActionScript tool with many (many!) features, which are listed here.
But if you're lazy:

Summary

FlashDevelop is a popular open source ActionScript 2/3 and web development environment.
FlashDevelop seemlessly integrates with Adobe Flash IDE, Adobe Flex SDK, Mtasc, Haxe and Swfmill.

Main Features

* AS3 Project management with seamless and optimized Adobe Flex SDK integration
* AS2 Project management with seamless Swfmill and Mtasc integration (using a portable standalone command line tool)
* Advanced ActionScript 2 and ActionScript 3 completion & code exploration with automatic classpath detection (even without project)
* Smart contextual Actionscript code generators
* SWF and SWC classes and symbols exploration
* Test movie in Adobe Flash IDE and with clickable error results (Flash CS3)
* MTASC compilation/code checking with clickable error results

Other Features

* Types Explorer
* Automatically cleans ASO files of modified AS2 classes
* Files explorer (can create Flash 8 Trust Files for you)
* Automatic JavaDoc creation from methods
* Smart Actionscript help websearch on F1
* Jump to class/member declaration on F4
* XML, HTML/PHP, JS, CSS code highlighting,
* Multibyte character encoding
* Program menu customization with XML files
* as2api GUI for documentation generation
* Snippets
* Lines bookmarks
* Code folding
* Zoom

Resources

* Special shortcuts for Actionscript coders
* Support: AS3, usefull threads to get started
* Support: AS2, usefull threads to get started
* Support: AS2, samples & tutorials
* Region folding in ActionScript
* Quick Build with @mtasc command (@mxmlc works the same)
* Argument processing in FlashDevelop (in menus or snippets)
* Contributing: getting started with FlashDevelop development
* Team members and contributors

(taken from the FlashDevelop site).

And the best... It's FREE! :D
AND OPENSOURCE! :D AND IS WRITEN IN C# (my mother language :3) :D

Ok, think I'm being a bit too happy...
Anyway, visit the website, be happy, and buy a beer to Emanuele! :D

6/01/2008

Making a blob in Flash part 3

Now, lets start working with constraints.

Let me explain:
There are 2 particles connected at a distance of 100px, and they're at a distance of 120px. If whe make a simple calcule:

er = ad-ds

where 'ad' is the actual distance and 'ds' is the constaint distance.

The result of this calcule may be 20, so whe divide it by two (two particles!) and the distance to add for both particles will be 10. The final calcule is this:

er = (ad-ds)/2;

Now, just move each particle in each other's direction in this amount.

Cool, isn't it? :D

Now, let's apply this script to a constraint script (based on Emanuele Feronato's script):

function constraint(p1,p2,dis){
dx = p1._x - p2._x;
dy = p1._y - p2._y;
actDis = Math.sqrt((dx*dx)+(dy*dy));
actDir = Math.atan2(dy,dx);
error = (actDis-dis)/2;
p1._x += Math.cos(actDir)*error;
p1._y += Math.sin(actDir)*error;
p2._x -= Math.cos(actDir)*error;
p2._y -= Math.sin(actDir)*error;
}


Pretty fancy, huh?
Now, let's apply this to a simulation:




particle1 = _root.createEmptyMovieClip("ball",_root.getNextHighestDepth());
particle1._x = Stage.width*.25;
particle1._y = Stage.height/2;

particle1.lineStyle(4,0,100);
particle1.beginFill(0xFFFF00,100);
particle1.moveTo(-15,-15);
particle1.lineTo(-15,15);
particle1.lineTo(15,15);
particle1.lineTo(15,-15);
particle1.moveTo(-15,-15);


particle2 = particle1.duplicateMovieClip("particle2",_root.getNextHighestDepth());
particle2._x = Stage.width*.75;
particle2._y = Stage.height/2;

setInterval(constraint,1000/24,particle1,particle2,300);

function constraint(p1,p2,dis){
dx = p1._x - p2._x;
dy = p1._y - p2._y;
actDis = Math.sqrt((dx*dx)+(dy*dy));
actDir = Math.atan2(dy,dx);
error = (actDis-dis)/2;
p1._x -= Math.cos(actDir)*error;
p1._y -= Math.sin(actDir)*error;
p2._x += Math.cos(actDir)*error;
p2._y += Math.sin(actDir)*error;
}

particle1.onPress = function(){
particle1.startDrag();
}
particle1.onRelease = function(){
particle1.stopDrag();
}
particle1.onReleaseOutside = function(){
particle1.stopDrag();
}



particle2.onPress = function(){
particle2.startDrag();
}
particle2.onRelease = function(){
particle2.stopDrag();
}
particle2.onReleaseOutside = function(){
particle2.stopDrag();
}



What would you see when you run it are two yellow squares on the screen, if you drag them, you may see that both squares react for the dragging.

---
Now, there's a issue that is really annoying: You attach some particles on the screen and constraint them, but they start to move left! What's happening? Well, what's happening is that Flash rounds some values (like x and y positions, alpha etc), so _x and _y are rounded down.
To fix that, instead of using _x and _y, create two vars named X and Y and on the particle's onEnterFrame function add a script to set _x and _Y positions to those X and Y vars.
---

Now, before add this to a verlet simulation, lets add a small function to limit particles position:



function stay_inside(b){
with(b){
X = Math.max(X,0+_width/2);
X = Math.min(X,Stage.width-_width/2);
Y = Math.max(Y,0+_height/2);
Y = Math.min(Y,Stage.height-_height/2);
}
}

And NOW you add it to a simulation, I have a ready script here, just paste it on root and run ;)




grav = .3;

// Create particle 1 and draw a square in it:
particle1 = _root.createEmptyMovieClip("ball",_root.getNextHighestDepth());
particle1._x = Stage.width*.25;
particle1._y = Stage.height/2;
particle1.X = particle1._x;
particle1.Y = particle1._y;
particle1.oldx = particle1._x;
particle1.oldy = particle1._y;

particle1.lineStyle(4,0,100);
particle1.beginFill(0xFFFF00,100);
particle1.moveTo(-15,-15);
particle1.lineTo(-15,15);
particle1.lineTo(15,15);
particle1.lineTo(15,-15);
particle1.moveTo(-15,-15);

// Now duplicates particle 1 in particle 2:
particle2 = particle1.duplicateMovieClip("particle2",_root.getNextHighestDepth());
particle2._x = Stage.width*.75;
particle2._y = Stage.height/2;
particle2.X = particle2._x;
particle2.Y = particle2._y;
particle2.oldx = particle2._x;
particle2.oldy = particle2._y;

// Runs everything:
function onEnterFrame(){
// Verlet particle 1:
verlet(particle1);
// Verlet particle 2:
verlet(particle2);

// constraint them togheter:
constraint(particle1,particle2,100);

// Don't let them go outside the screen!:
stay_inside(particle1);
stay_inside(particle2);

// This part draws a line between the two particles:
_root.clear();
_root.lineStyle(4,0,100);
_root.moveTo(particle1.X,particle1.Y);
_root.lineTo(particle2.X,particle2.Y);
}

function constraint(p1,p2,dis){
dx = p1.X - p2.X;
dy = p1.Y - p2.Y;
actDis = Math.sqrt((dx*dx)+(dy*dy));
actDir = Math.atan2(dy,dx);
error = (actDis-dis)/2;
p1.X -= Math.cos(actDir)*error;
p1.Y -= Math.sin(actDir)*error;
p2.X += Math.cos(actDir)*error;
p2.Y += Math.sin(actDir)*error;
}

particle1.onPress = function(){
particle1.drag = true;
}
particle1.onRelease = function(){
particle1.drag = false;
}
particle1.onReleaseOutside = function(){
particle1.drag = false;
}
particle1.onEnterFrame = function(){
if(particle1.drag){
particle1.X = _root._xmouse;
particle1.Y = _root._ymouse;
}
particle1._x = particle1.X;
particle1._y = particle1.Y;
}


particle2.onPress = function(){
particle2.drag = true;
}
particle2.onRelease = function(){
particle2.drag = false;
}
particle2.onReleaseOutside = function(){
particle2.drag = false;
}
particle2.onEnterFrame = function(){
if(particle2.drag){
particle2.X = _root._xmouse;
particle2.Y = _root._ymouse;
}
particle2._x = particle2.X;
particle2._y = particle2.Y;
}


function stay_inside(b){
with(b){
X = Math.max(X,0+_width/2);
X = Math.min(X,Stage.width-_width/2);
Y = Math.max(Y,0+_height/2);
Y = Math.min(Y,Stage.height-_height/2);
}
}

function verlet(b){
with(b){
tempx = X;
tempy = Y;
X = X + (X - oldx);
Y = Y + (Y - oldy);
Y += _root.grav;
oldx = tempx;
oldy = tempy;
}
}



And this is the result:





Next up is the spring system! :D


Goodbye, and thanks for reading ;)

5/28/2008

Making a blob in Flash part 2

Now, lets start for real!

And lets start with the base of our blob: The Verlet implementation.
I can't really explain what is verlet, it's simply the best (and easiest) way to simulate real movements in computer. It may look simple, but is very powerful!

And here's the Flash version of it:

  1. function verlet(particle){
  2. with(particle){
  3. if(oldx == undefined or oldy == undefined){
  4. oldx = _x;
  5. oldy = _y;
  6. }
  7. tempx = _x;
  8. tempy = _y;
  9. _x = _x + (_x - oldx);
  10. _y = _y + (_y - oldy);
  11. oldx = tempx;
  12. oldy = tempy;
  13. }
  14. }

It may looks quite simple, but is not! It works this way:

2: It calls the particle and amkes the particle execute the following code
3, 4, 5: It checks whether the two variables (oldx,oldy) exists, if not, create them
8, 9: Stores the current position in two temporary variables.
11, 12: Moves the particle based on the last position, that is, if last x position is 5, and current x position is 10, then calculates (10-5) and apply it
14, 15: Now store the last position (before the last calculation) in the oldx and oldy variables.

See? Simple, hun? Now, lets test it! :D


_root.createEmptyMovieClip("verlet1",_root.getNextHighestDepth());
grav = .3;

verlet1._x = Stage.width/2;
verlet1._y = Stage.height/2;

verlet1.lineStyle(2,0,100);
verlet1.beginFill(0xFF0000,100);
verlet1.moveTo(-15,-15);
verlet1.lineTo(-15,15);
verlet1.lineTo(15,15);
verlet1.lineTo(15,-15);
verlet1.lineTo(-15,-15);
verlet1.endFill();

function onEnterFrame(){
verlet(verlet1);
verlet1._y += _root.grav;
}

function verlet(particle){
with(particle){
if(oldx == undefined or oldy == undefined){
oldx = _x;
oldy = _y;
}

tempx = _x;
tempy = _y;

_x = _x + (_x - oldx);
_y = _y + (_y - oldy);

oldx = tempx;
oldy = tempy;
}
}


Now, what you may see when paste and execute this code on Flash is a red box falling on the stage. Nothing more, but it may be more complex if implemented a constraint script.
This, and more, at the next part ;)

5/27/2008

Making a blob in Flash part 1

I was wandering around triquitips and I saw an thread about how to make a soft body physics in Flash.
It took me some time to make, but I just finished a simple 'soft body' exapmple:

http://www.swfme.com/view/1175742

Well, it's quite simple and basic, but that's the idea.
I'm going to guide you throught all world of Physics, starting with verlet, constraints, and all other maths involved in the making of a blob.

So, stay toned!

5/21/2008

Hello everyone!

Hi, My name is Luiz and I'm a casual Flash game developer, which means that I don't make games for commercial (i.e. not free) intentions.

In this blog I'll log my progress as a gme developer and I'll make also some tutorials.

And as a new blog, it deserves a glorious first post, right?! :D
Nop! As I don't have time now. :(
But 'til tomorrow I'll post something useful....

Stay tunned!