Ah - I see your problem now... you're not clearing the background each frame. That's an easy enough mistake to make when moving from Flash.
If you want to animate something in Processing you start by clearing the background and then draw your object in the new position; or in your case at its new opacity; and you do that every frame. So you're not changing the location or opacity of the existing rectangle; you're removing it completely and drawing a new one... I suspect Flash is nice enough to do that in the background without exposing us to the complexities involved.
So with some minor adjustments your rectangle will fade:
Code://main class
boolean onOff;
int dragX,dragY,moveX, moveY;
PVector click,drag;
MyRect r;
void setup(){
size (800, 800);
frameRate(30);
background(255);
click= new PVector (0,0);
drag= new PVector(0,0);
}
void draw(){
// Draw background every frame, not just in setup
background(255);
onOff=false;
if ((keyPressed) && (key=='s')){
onOff=true;
moveX=mouseX;
moveY=mouseY;
r = new MyRect(click.x, click.y, moveX-click.x, moveY-click.y);
}
if(r != null){
r.display();
}
}
void mouseReleased(){
drag.set(mouseX,mouseY,0);
}
void mousePressed(){
if ((keyPressed==true) && (key== 's')){
click.set(mouseX, mouseY,0);
drag.set(mouseX, mouseY,0);
}
else {
onOff=false;
}
}
//////// MyRect class
class MyRect{
float x,y, rWidth,rHeight;
int alfa=155;
boolean fade;
MyRect(float rX, float rY, float rW, float rH){
x=rX;
y=rY;
rWidth=rW;
rHeight= rH;
}
void display(){
stroke (0,alfa);
noFill();
rect(x,y,rWidth,rHeight);
if (alfa>0){
alfa--;
}
}
}//close class
Of course the problem you'll find you have now is that you can only draw one rectangle at a time and that's where the array comes in; though in actual fact I'd be tempted to use an ArrayList - there's some awkward syntax involved but when working with objects they offer better functionality than plain arrays...