Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become an Expert!

Join 244,261 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,306 people online right now. Registration is fast and FREE... Join Now!




Flash Challenge #1 - A rectangle

2 Pages V  1 2 >  
Reply to this topicStart new topic

Flash Challenge #1 - A rectangle, Discussion

pioSko
19 May, 2006 - 10:13 AM
Post #1

still.dreaming
Group Icon

Joined: 6 Jun, 2003
Posts: 1,888



Thanked: 13 times
Dream Kudos: 225
My Contributions
Discuss and post solutions to Challenge #1

User is offlineProfile CardPM
+Quote Post


1lacca
RE: Flash Challenge #1 - A Rectangle
20 May, 2006 - 11:16 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 22 times
My Contributions
Nice!
I have only one question: how big (dimensions) the flash object is supposed to be?
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Flash Challenge #1 - A Rectangle
20 May, 2006 - 11:23 AM
Post #3

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 22 times
My Contributions
Ah ok, two more:
- positioned at: does it mean the position of the upper left corner, or the center of the rectangle?
- rectangle: is this the border of the rectangle, or a filled one? - although looking at the more advanced questions I think you mean the border only.
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Flash Challenge #1 - A Rectangle
20 May, 2006 - 02:08 PM
Post #4

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 22 times
My Contributions
Haha, looks-like I'm hijacking this thread smile.gif
So another question:
In #4 and #5 you write "When pressed and dragged, the side should move and follow the mouse along one axis." Is that the parallel, or the perpendicular axis relative to the dragged side?
User is offlineProfile CardPM
+Quote Post

pioSko
RE: Flash Challenge #1 - A Rectangle
21 May, 2006 - 06:40 AM
Post #5

still.dreaming
Group Icon

Joined: 6 Jun, 2003
Posts: 1,888



Thanked: 13 times
Dream Kudos: 225
My Contributions
The dimentions aren't as important as the technique used to create the rectangle smile.gif if not mentioned just improvise

Position of top left corner.

Resizing: If you move the right edge of the rectangle, it may only move along the x axis... altering the rectangle's width
User is offlineProfile CardPM
+Quote Post

pioSko
RE: Flash Challenge #1 - A Rectangle
22 May, 2006 - 12:58 PM
Post #6

still.dreaming
Group Icon

Joined: 6 Jun, 2003
Posts: 1,888



Thanked: 13 times
Dream Kudos: 225
My Contributions
1lacca's solutions in OpenLaszlo

Good work, dude.

Now lets see some Flash answers smile.gif
User is offlineProfile CardPM
+Quote Post

red01
RE: Flash Challenge #1 - A Rectangle
23 May, 2006 - 08:11 PM
Post #7

D.I.C Head
Group Icon

Joined: 8 May, 2006
Posts: 186



Thanked: 1 times
Dream Kudos: 25
My Contributions
Part I

CODE

var mcSquare:MovieClip = this.createEmptyMovieClip("square_mc",100);

var nStartXPos:Number = 200
var nStartYPos:Number = 200
var nSqHeight:Number = 100;
var nSqWidth:Number = 200;

var nLeft = 0
var nTop:Number = 0
var nRight:Number = nSqWidth
var nBottom:Number = nSqHeight
var nLeft:Number = 0



function buildSquare(){
    mcSquare._x = nStartXPos
    mcSquare._y = nStartYPos
    mcSquare.lineStyle(2,0x000000,100)
    mcSquare.beginFill(0xeeeeee,100)
    mcSquare.moveTo(nLeft,nTop)
    mcSquare.lineTo(nRight,nTop)
    mcSquare.lineTo(nRight,nBottom)
    mcSquare.lineTo(nLeft,nBottom)
    mcSquare.lineTo(nLeft,nTop)
    mcSquare.endFill()
}
buildSquare()

User is offlineProfile CardPM
+Quote Post

red01
RE: Flash Challenge #1 - A Rectangle
23 May, 2006 - 08:18 PM
Post #8

D.I.C Head
Group Icon

Joined: 8 May, 2006
Posts: 186



Thanked: 1 times
Dream Kudos: 25
My Contributions
Part 3

I could have done this a bit smarter, but eh.......

also this is centered, just copy and paste into actionscript

CODE


var nSquareWidth:Number = 200;
var nSquareHeight:Number = 100;
var nStageHeight:Number = 400;
var nStageWidth:Number = 550;

var nTop:Number = 0 - (nSquareHeight/2)
var nRight:Number = nSquareWidth/2
var nBottom:Number = nSquareHeight/2
var nLeft:Number = 0 -(nSquareHeight/2)


var sColUp:String ="000099"
var sColOver:String ="990000"
var sColDown:String = "009900"

var nDepth:Number =100;

var mcSquare:MovieClip = this.createEmptyMovieClip("square_mc",100);




function buildSquare(){
    mcSquare._x = nStageWidth / 2
    mcSquare._y = nStageHeight / 2

    //mcSquare.lineStyle(2,0x000000,100)
    mcSquare.beginFill(0xeeeeee,100)
    mcSquare.moveTo(nLeft,nTop)
    mcSquare.lineTo(nRight,nTop)
    mcSquare.lineTo(nRight,nBottom)
    mcSquare.lineTo(nLeft,nBottom)
    mcSquare.lineTo(nLeft,nTop)
    mcSquare.endFill()
    
    setBtns()    

}
buildSquare()


function drawBtnLine(sBrush:Number, sColor:String, mcDrawIn:MovieClip, startPos:Array, endPos:Array){
    mcDrawIn.line_mc.removeMovieClip();
    var mcLine:MovieClip = mcDrawIn.createEmptyMovieClip("line_mc",100);
    mcLine.lineStyle(sBrush,parseInt(sColor,16),100)
    mcLine.moveTo(startPos[0],startPos[1])
    mcLine.lineTo(endPos[0],endPos[1])
}


function render(){
    drawBtnLine(2, sColUp, mcSquare.top_btn, [nLeft,nTop], [nRight,nTop])
    drawBtnLine(2, sColUp, mcSquare.right_btn,[nRight,nTop], [nRight,nBottom])
    drawBtnLine(2, sColUp, mcSquare.bottom_btn,[nRight,nBottom], [nLeft,nBottom])
    drawBtnLine(2, sColUp, mcSquare.left_btn, [nLeft,nBottom], [nLeft,nTop])
}


function setBtns(){
        
    var mcTopBtn:MovieClip = mcSquare.createEmptyMovieClip("top_btn",nDepth)
    mcTopBtn.arrStartPos = arrStartPos
    mcTopBtn.arrEndPos = arrEndPos
    nDepth++
    mcTopBtn.onRollOver = function(){
        drawBtnLine(2,sColOver,this,[nLeft,nTop],[nRight,nTop])
    }
    mcTopBtn.onRollOut = function(){
        drawBtnLine(2,sColUp,this,[nLeft,nTop],[nRight,nTop])
    }
    mcTopBtn.onPress = function(){
        drawBtnLine(3,sColDown,this,[nLeft,nTop],[nRight,nTop])
    }
    mcTopBtn.onReleaseOutside = function(){
        drawBtnLine(2,sColUp,this,[nLeft,nTop],[nRight,nTop])
    }
    mcTopBtn.onRelease = function(){
        drawBtnLine(2,sColUp,this,[nLeft,nTop],[nRight,nTop])
    }
    
    
    
    var mcBottomBtn:MovieClip = mcSquare.createEmptyMovieClip("bottom_btn",nDepth)
    nDepth++
    mcBottomBtn.onRollOver = function(){
        drawBtnLine(2,sColOver,this,[nRight,nBottom],[nLeft,nBottom])
    }
    mcBottomBtn.onRollOut = function(){
        drawBtnLine(2,sColUp,this,[nRight,nBottom],[nLeft,nBottom])
    }
    mcBottomBtn.onPress = function(){
        drawBtnLine(3,sColDown,this,[nRight,nBottom],[nLeft,nBottom])
    }
    mcBottomBtn.onReleaseOutside = function(){
        drawBtnLine(2,sColUp,this,[nRight,nBottom],[nLeft,nBottom])
    }
    mcBottomBtn.onRelease = function(){
        drawBtnLine(2,sColUp,this,[nRight,nBottom],[nLeft,nBottom])
    }

    
    var mcLeftBtn:MovieClip = mcSquare.createEmptyMovieClip("left_btn",nDepth)
    nDepth++
    mcLeftBtn.onRollOver = function(){
        drawBtnLine(2,sColOver,this,[nLeft,nBottom],[nLeft,nTop])
    }
    mcLeftBtn.onRollOut = function(){
        drawBtnLine(2,sColUp,this,[nLeft,nBottom],[nLeft,nTop])
    }
    mcLeftBtn.onPress = function(){
        drawBtnLine(3,sColDown,this,[nLeft,nBottom],[nLeft,nTop])
    }
    mcLeftBtn.onReleaseOutside = function(){
        drawBtnLine(2,sColUp,this,[nLeft,nBottom],[nLeft,nTop])
    }
    mcLeftBtn.onRelease = function(){
        drawBtnLine(2,sColUp,this,[nLeft,nBottom],[nLeft,nTop])
}
    

    var mcRightBtn:MovieClip = mcSquare.createEmptyMovieClip("right_btn",nDepth)
    nDepth++
    mcRightBtn.onRollOver = function(){
        drawBtnLine(2,sColOver,this,[nRight,nTop],[nRight,nBottom])
    }
    mcRightBtn.onRollOut = function(){
        drawBtnLine(2,sColUp,this,[nRight,nTop],[nRight,nBottom])
    }
    mcRightBtn.onPress = function(){
        drawBtnLine(3,sColDown,this,[nRight,nTop],[nRight,nBottom])
    }
    mcRightBtn.onReleaseOutside = function(){
        drawBtnLine(2,sColUp,this,[nRight,nTop],[nRight,nBottom])
    }
    mcRightBtn.onRelease = function(){
        drawBtnLine(2,sColUp,this,[nRight,nTop],[nRight,nBottom])
    }

    render()
    
}



smile.gif

This post has been edited by red01: 23 May, 2006 - 08:22 PM
User is offlineProfile CardPM
+Quote Post

pioSko
RE: Flash Challenge #1 - A Rectangle
23 May, 2006 - 10:40 PM
Post #9

still.dreaming
Group Icon

Joined: 6 Jun, 2003
Posts: 1,888



Thanked: 13 times
Dream Kudos: 225
My Contributions
Good one... smile.gif Code works great... and you're right, it can still be simplified. But, a good example of thinking ahead.
Part I can be done simply by doing...
CODE
this.lineStyle(2, 0x000000, 100);
this.moveTo(200, 200);
this.lineTo(400, 200);
this.lineTo(400, 300);
this.lineTo(200, 300);
this.lineTo(200, 200);

.. but you did something I was hoping someone would do and that was to prepare for the next Parts right at the beginning. It may take more time somtimes, but creating "modules" like yours increases productivity and function of the overall project.

Your way is one of two main ways of doing small "modules". There is another way, very similar to a function, but is a bit more flexible wink2.gif

(there are three actually, but the third is a bit more advanced and requires external files and Flash preferences modification.. won't go into it just yet)


Are you attempting parts IV and V?
User is offlineProfile CardPM
+Quote Post

red01
RE: Flash Challenge #1 - A Rectangle
24 May, 2006 - 04:12 PM
Post #10

D.I.C Head
Group Icon

Joined: 8 May, 2006
Posts: 186



Thanked: 1 times
Dream Kudos: 25
My Contributions
Part IV

Yea I could have made some classes to handle this but oh well........

im using nDepth to control the depth of the mc's on the stage... this gets around the getNextHighestDepth bug in flash 6



This is very long winded, again could have streamlined alot but here it is.....


Just copy and paste in to actionscript

Note: this also centers the box in the stage

CODE
stop();

var isDown:Boolean = false;
var isDragging:Boolean = false;
var nSquareWidth:Number = 200;
var nSquareHeight:Number = 200;
var nStageHeight:Number = 400;
var nStageWidth:Number = 550;

var isTop:Boolean = false
var isRight:Boolean = false
var isBottom:Boolean = false
var isLeft:Boolean = false

var nTextFeildLength:Number = 50
var nTextFeildHeight:Number = 20
var nTextFeildSpace:Number = 20

var nTop:Number = 0 - (nSquareHeight/2)
var nRight:Number = nSquareWidth/2
var nBottom:Number = nSquareHeight/2
var nLeft:Number = 0 -(nSquareHeight/2)


var sColUp:String ="000099"
var sColOver:String ="990000"
var sColDown:String = "009900"

var nDepth:Number =100;

var mcSquare:MovieClip = this.createEmptyMovieClip("square_mc",100);


onMouseDown = function(){
    isDown = true;
}

onMouseUp = function(){
    isDown = false;
    isTop = false;
    isRight = false;
    isBottom = false;
    isLeft = false;
    render()
}

function buildSquare(){
    mcSquare._x = nStageWidth / 2
    mcSquare._y = nStageHeight / 2
    setBtns()    

}
buildSquare()


onMouseMove = function(){
    if(isDown && isDragging){
        nTop = mcSquare.top_btn._y
        nRight = mcSquare.right_btn._x
        nBottom =  mcSquare.bottom_btn._y
        nLeft = mcSquare.left_btn._x
        
        nSquareHeight = mcSquare.bottom_btn._y - mcSquare.top_btn._y
        //trace(nSquareHeight)
        nSquareWidth = mcSquare.right_btn._x - mcSquare.left_btn._x
        trace(nSquareWidth)
        render();
    }
}

function drawBtnLine(sBrush:Number, sColor:String, mcDrawIn:MovieClip, startPos:Array, endPos:Array){
    mcDrawIn.line_mc.removeMovieClip();
    var mcLine:MovieClip = mcDrawIn.createEmptyMovieClip("line_mc",100);
    mcLine.lineStyle(sBrush,parseInt(sColor,16),100)
    mcLine.moveTo(startPos[0],startPos[1])
    mcLine.lineTo(endPos[0],endPos[1])
}


function render(){
        drawBtnLine(2, sColUp, mcSquare.top_btn, [nLeft,0], [nRight,0])
        drawBtnLine(2, sColUp, mcSquare.right_btn,[0,nTop], [0,nBottom])
        drawBtnLine(2, sColUp, mcSquare.bottom_btn,[nRight,0], [nLeft,0])
        drawBtnLine(2, sColUp, mcSquare.left_btn, [0,nBottom], [0,nTop])

        
    // turn Colour back if mouse down mouse down
    if(isTop){
        drawBtnLine(3, sColDown, mcSquare.top_btn, [nLeft,0], [nRight,0])
    }else if(isBottom){
        drawBtnLine(3, sColDown, mcSquare.bottom_btn,[nRight,0], [nLeft,0])
    }else if(isRight){
        drawBtnLine(3, sColDown, mcSquare.right_btn,[0,nTop], [0,nBottom])
    }else if(isLeft){
        drawBtnLine(3, sColDown, mcSquare.left_btn, [0,nBottom], [0,nTop])    
    }
    
    
    
    //TOP Di
    mcSquare.topWidth_txt.text = nSquareWidth.toString();    
    mcSquare.topWidth_txt._x =  (nLeft + (nSquareWidth/2)) - (nTextFeildLength/2)
    mcSquare.topWidth_txt._y = mcSquare.top_btn._y - nTextFeildSpace
    mcSquare.topWidth_txt.selectable = false
    //BOTTOM Di
    mcSquare.bottomWidth_txt.text = nSquareWidth.toString();    
    mcSquare.bottomWidth_txt._x =  (nLeft + (nSquareWidth/2)) - (nTextFeildLength/2)
    mcSquare.bottomWidth_txt._y = mcSquare.bottom_btn._y
    mcSquare.bottomWidth_txt.selectable = false
    
    mcSquare.leftHeight_txt.text = nSquareHeight.toString();    
    mcSquare.leftHeight_txt._x =  mcSquare.left_btn._x - nTextFeildLength - nTextFeildSpace
    mcSquare.leftHeight_txt._y =  (nTop + (nSquareHeight/2)) - (nTextFeildHeight/2)
    mcSquare.leftHeight_txt.selectable = false
    
    mcSquare.rightHeight_txt.text = nSquareHeight.toString();    
    mcSquare.rightHeight_txt._x =  mcSquare.right_btn._x + nTextFeildSpace
    mcSquare.rightHeight_txt._y =  (nTop + (nSquareHeight/2)) - (nTextFeildHeight/2)    
    mcSquare.rightHeight_txt.selectable = false
    
    var txtFmt:TextFormat = new TextFormat();
    txtFmt.align = "center"
    mcSquare.topWidth_txt.setTextFormat(txtFmt);
    mcSquare.bottomWidth_txt.setTextFormat(txtFmt);
    
    txtFmt.align = "right"
    mcSquare.leftHeight_txt.setTextFormat(txtFmt)
    
    txtFmt.align = "left"
    mcSquare.rightHeight_txt.setTextFormat(txtFmt)
}


function setBtns(){
    var mcTopBtn:MovieClip = mcSquare.createEmptyMovieClip("top_btn",nDepth)
    mcTopBtn._y = 0 - (nSquareHeight/2)
    mcTopBtn.arrStartPos = arrStartPos
    mcTopBtn.arrEndPos = arrEndPos
    nDepth++
    
    mcTopBtn.onRollOver = function(){
        drawBtnLine(2,sColOver,this,[nLeft,0],[nRight,0])
    }
    mcTopBtn.onRollOut = function(){
        drawBtnLine(2,sColUp,this,[nLeft,0],[nRight,0])
    }
    mcTopBtn.onPress = function(){
        drawBtnLine(3,sColDown,this,[nLeft,0],[nRight,0])
        this.startDrag(false,this._x,0-(nStageHeight / 2),this._x,500)
        isDragging = true;
        isTop = true;
    }
    mcTopBtn.onReleaseOutside = function(){
        drawBtnLine(2,sColUp,this,[nLeft,0],[nRight,0])
        this.stopDrag();
        isDragging = false;
    }
    mcTopBtn.onRelease = function(){
        drawBtnLine(2,sColUp,this,[nLeft,nTop],[nRight,nTop])
        this.stopDrag();
        isDragging = false;
    }
    
    
    
    var mcBottomBtn:MovieClip = mcSquare.createEmptyMovieClip("bottom_btn",nDepth)
    nDepth++
     mcBottomBtn._y = 0 + (nSquareHeight/2)
    
    mcBottomBtn.onRollOver = function(){
        drawBtnLine(2,sColOver,this,[nRight,0],[nLeft,0])
    }
    mcBottomBtn.onRollOut = function(){
        drawBtnLine(2,sColUp,this,[nRight,0],[nLeft,0])
    }
    mcBottomBtn.onPress = function(){
        isDragging = true;
        drawBtnLine(3,sColDown,this,[nRight,0],[nLeft,0])
        this.startDrag(false,this._x,0-(nStageHeight / 2),this._x,500)
        isBottom = true
    }
    mcBottomBtn.onReleaseOutside = function(){
        drawBtnLine(2,sColUp,this,[nRight,0],[nLeft,0])
        this.stopDrag();
        isDragging = false;
    }
    mcBottomBtn.onRelease = function(){
        drawBtnLine(2,sColUp,this,[nRight,0],[nLeft,0])
        this.stopDrag();
        isDragging = false;
    }
    
    
    
    
    
    var mcLeftBtn:MovieClip = mcSquare.createEmptyMovieClip("left_btn",nDepth)
    nDepth++
    mcLeftBtn._x = 0 - (nSquareWidth/2)
    mcLeftBtn.onRollOver = function(){
        drawBtnLine(2,sColOver,this,[0,nBottom],[0,nTop])
    }
    mcLeftBtn.onRollOut = function(){
        drawBtnLine(2,sColUp,this,[0,nBottom],[0,nTop])
    }
    mcLeftBtn.onPress = function(){
        isDragging = true;
        drawBtnLine(3,sColDown,this,[0,nBottom],[0,nTop])
        this.startDrag(false,0-(nStageWidth / 2),this._y,500,this._y)
        isLeft=true
    }
    mcLeftBtn.onReleaseOutside = function(){
        drawBtnLine(2,sColUp,this,[0,nBottom],[0,nTop])
        this.stopDrag();
    }
    mcLeftBtn.onRelease = function(){
        drawBtnLine(2,sColUp,this,[0,nBottom],[0,nTop])
        this.stopDrag();
    }
    
    
    
    
    var mcRightBtn:MovieClip = mcSquare.createEmptyMovieClip("right_btn",nDepth)
    nDepth++
    mcRightBtn._x = 0 + (nSquareWidth/2)
    
    mcRightBtn.onRollOver = function(){
        drawBtnLine(2,sColOver,this,[0,nTop],[0,nBottom])
    }
    mcRightBtn.onRollOut = function(){
        drawBtnLine(2,sColUp,this,[0,nTop],[0,nBottom])
    }
    mcRightBtn.onPress = function(){
        isDragging = true;
        drawBtnLine(3,sColDown,this,[0,nTop],[0,nBottom])
        this.startDrag(false,0-(nStageWidth / 2),this._y,500,this._y)
        isRight = true
    }
    mcRightBtn.onReleaseOutside = function(){
        drawBtnLine(2,sColUp,this,[0,nTop],[0,nBottom])
        this.stopDrag();
        isDragging = false;
    }
    mcRightBtn.onRelease = function(){
        drawBtnLine(2,sColUp,this,[0,nTop],[0,nBottom])
        this.stopDrag();
        isDragging = false;
    }
    
    mcSquare.createTextField("topWidth_txt", nDepth,mcTopBtn._x, mcTopBtn._y, nTextFeildLength, nTextFeildHeight);
    nDepth++
    mcSquare.createTextField("bottomWidth_txt", nDepth,mcBottomBtn._x, mcBottomBtn._y, nTextFeildLength, nTextFeildHeight);
    nDepth++
    mcSquare.createTextField("leftHeight_txt", nDepth,mcLeftBtn._x - nTextFeildSpace, mcLeftBtn._y, nTextFeildLength, nTextFeildHeight);
    nDepth++
    mcSquare.createTextField("rightHeight_txt", nDepth,mcRightBtn._x - nTextFeildSpace, mcRightBtn._y, nTextFeildLength, nTextFeildHeight);
    nDepth++
    render();
    
}





Peace Out.........

This post has been edited by red01: 24 May, 2006 - 04:16 PM
User is offlineProfile CardPM
+Quote Post

pioSko
RE: Flash Challenge #1 - A Rectangle
24 May, 2006 - 11:05 PM
Post #11

still.dreaming
Group Icon

Joined: 6 Jun, 2003
Posts: 1,888



Thanked: 13 times
Dream Kudos: 225
My Contributions
I have two corrections for you smile.gif

#1 - You can't have negative lengths wink2.gif This is simple to fix. Just but a Math.abs() around your values.

#2 - There is a significant delay in redrawing the rectangle when moving a side. The sides that are being resized aren't catching up with the moving side. It may be detail but clients/editors don't accept it and 99% of the time will tell you to fix it.

If you want, fix it.. or move on to Part V and leave it for somebody else to try and fix/simplify your code wink2.gif

Overall, great job.. especially for not using library objects. Two thumbs up.
User is offlineProfile CardPM
+Quote Post

red01
RE: Flash Challenge #1 - A Rectangle
25 May, 2006 - 01:48 AM
Post #12

D.I.C Head
Group Icon

Joined: 8 May, 2006
Posts: 186



Thanked: 1 times
Dream Kudos: 25
My Contributions
Yea i think im going to re-code (that is some nasty code crazy.gif ), i just chucked it together with little or no thought......


Stay tuned for simplified version.
User is offlineProfile CardPM
+Quote Post

bigdawg24
RE: Flash Challenge #1 - A Rectangle
25 Aug, 2007 - 07:12 PM
Post #13

D.I.C Head
**

Joined: 18 Aug, 2007
Posts: 207


My Contributions
The problem I would have with #1 would go along with the problem I am having attempting to develop a flash website. I have a question thread in the FLASH & ACTIONSCRIPT forumn but its just been ignored.
User is offlineProfile CardPM
+Quote Post

DilutedImage
RE: Flash Challenge #1 - A Rectangle
26 Aug, 2007 - 12:27 AM
Post #14

D.I.C Addict
Group Icon

Joined: 20 Nov, 2006
Posts: 644



Thanked: 9 times
Dream Kudos: 25
My Contributions
This thread is for the discussion of the Flash Challenge. Attempting to hijack this thread, in an effort to get your question answered quicker, will only discourage others from wanting to help you.

I'm reminded of the song "Cry Me a River" biggrin.gif .. . Nobody is ignoring you. The people in this forum are not paid to answer your questions. We're just fellow coders who hop online and help when we can. So forgive us all if we didn't get to your question fast enough – a question that could have been answered by simply reading Section 1 of the Help Documentation.

User is offlineProfile CardPM
+Quote Post

bigdawg24
RE: Flash Challenge #1 - A Rectangle
26 Aug, 2007 - 07:19 AM
Post #15

D.I.C Head
**

Joined: 18 Aug, 2007
Posts: 207


My Contributions
I suppose I should justify myself here just a second. I havent been on forums a great detail; although I have been on newsgroups of old quite a bit and its of course not to much different (in its own way). I didn't realize that my determination to get a quick answer that I knew should have been an easy solution would be considered hijacking. Frankly...its my bad (my apologies). I know people take these forums seriously, which is why I am here. Individuals give solid answers and give their time which is great.

So, if anyone took my antics as hijacking then I apologize; BUT, the challenge question had a lot to do with a step in my own project I was attempting thus I resourced it as well.
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Flash Challenge #1 - A Rectangle
26 Aug, 2007 - 07:23 AM
Post #16

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 16,441



Thanked: 117 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
feel free to bump your thread with a polite "bump" if it's been more than a few days.
User is offlineProfile CardPM
+Quote Post

DilutedImage
RE: Flash Challenge #1 - A Rectangle
26 Aug, 2007 - 03:25 PM
Post #17

D.I.C Addict
Group Icon

Joined: 20 Nov, 2006
Posts: 644



Thanked: 9 times
Dream Kudos: 25
My Contributions
QUOTE
BUT, the challenge question had a lot to do with a step in my own project I was attempting

The challenge is an ActionScript challenge, revolving around a script-generated rectangle. Your question is about modifying a rectangle shape object with drawing tools. The two problems are completely unrelated.

I can understand where you're coming from though. You're anxious to learn, and can't get answers quick enough. Nobody can hold that against you; it's a great thing. Just be aware that others desire to learn as well, and it's a lot easier when things stay organized and on-topic. Like Skyhawk stated, just do a simple "bump" post to get your thread back to the top.

Of course, it also couldn't hurt to read the Using Flash portion of the documentation, so that you've got a firm foundation to build your skills upon. wink2.gif


Now, we know you meant no ill intent, and won't hold it against you, so let's let this topic die, and leave this thread for discussing the challenge.
User is offlineProfile CardPM
+Quote Post

brandon_v
RE: Flash Challenge #1 - A Rectangle
30 May, 2008 - 04:02 AM
Post #18

New D.I.C Head
*

Joined: 29 May, 2008
Posts: 44



Thanked: 1 times
My Contributions
Ok guys,
This thread seems kinda dead, but I gave some of the challenges a try.
I redid part 3 to be more simplistic, yet still 100% functional:

CODE

/*
Draw a rectangle anywhere on the stage, with dimentions 200px by 100px.
Eash side of the rectangle must react to mouse interaction (like a button)
with the following styles for states: on up #000099 2px, on over #990000 2px,
on down #009900 3px.
*/

var colUp:String = "000099";
var colOver:String = "990000";
var colDown:String = "009900";
var width:Number = 200;
var height:Number = 100;
var size1:Number = 2;
var size2:Number = 3;

var box:Object = {
    width: width,
    height: height,
    halfw: width/2,
    halfh: height/2
};

var centre:Object = {
    x: Stage.width/2  - box.halfw,
    y: Stage.height/2 - box.halfh
}

var coordx = centre.x;
var coordy = centre.y;

var points:Object = {
    a: p(0, 0),                     //    a ----- b
    b: p(box.width, 0),             //    |        |
    c: p(0, box.height),             //    c ----- d
    d: p(box.width, box.height)
};

_root.onLoad = function()
{
    initializeRect();
    render();
    addButtons();
}

function p (x, y)
{
    return new toPoint(x, y);
}
function toPoint (x, y)
{
    this.x = x;
    this.y = y;
}

function initializeRect()
{
    var i:Number = 0;
    _root.createEmptyMovieClip("rectangle", i);
    rectangle._x = coordx;
    rectangle._y = coordy;
    rectangle.createEmptyMovieClip("btn_top", i++);
    rectangle.createEmptyMovieClip("btn_bottom", i++);
    rectangle.createEmptyMovieClip("btn_left", i++);
    rectangle.createEmptyMovieClip("btn_right", i++);
}
function render()
{
    createSideBtns(size1, rectangle.btn_top, colUp, points.a, points.b);
    createSideBtns(size1, rectangle.btn_bottom, colUp, points.c, points.d);
    createSideBtns(size1, rectangle.btn_left, colUp, points.a, points.c);
    createSideBtns(size1, rectangle.btn_right, colUp, points.b, points.d);
}

function createSideBtns(size, container, colour, startPos, stopPos)
{
    container.genericContainer.removeMovieClip();
    var line = container.createEmptyMovieClip("genericContainer", 1);
    line.lineStyle(size, "0x" + colour);
    line.moveTo(startPos.x, startPos.y);
    line.lineTo(stopPos.x, stopPos.y);
}

function addButtons()
{
    convert(rectangle.btn_top, points.a, points.b);
    convert(rectangle.btn_bottom, points.c, points.d);
    convert(rectangle.btn_left, points.a, points.c);
    convert(rectangle.btn_right, points.b, points.d);
}
function convert(object, startPos, stopPos)
{
    object.onRollOver = function()
    {
        createSideBtns(size1, this, colOver, startPos, stopPos);
    }
    object.onRollOut = function()
    {
        createSideBtns(size1, this, colUp, startPos, stopPos);
    }
    object.onRelease = function()
    {
        createSideBtns(size1, this, colUp, startPos, stopPos);
    }
    object.onPress = function()
    {
        createSideBtns(size2, this, colDown, startPos, stopPos);
    }
    object.onDragOut = function()
    {
        createSideBtns(size1, this, colUp, startPos, stopPos);
    }
}


I know it's kinda useless, but I thought I'd give my AS skills a try.
It's probably best to copy + paste it if you want to look through it.
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Flash Challenge #1 - A Rectangle
12 Jul, 2008 - 12:56 AM
Post #19

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 3,810



Thanked: 203 times
Dream Kudos: 1325
My Contributions
Okay, here is my version of the Holy Shit (Part V).

I decided to add some fills to the whole thing, and allowing for gradients, and I also chose not to worry about placing the left and bottom text fields (or even creating them) because they just display the same information as the top and right ones do. 255 lines in total. It probably isn't the most clean code out there, or even the smallest possible, but it works form what I can tell.

<prePostEdit>
I actually was reading over the Holy Shit requirements again befor eposting and realized that he said "rotate" not "resize" so I am posting both where the circles are used to resize from the corners and where the circles are used to rotate the rectangle.

The rotate portion is a bit more troublesome and I am sure that someone will be able to edit it to work better but at this point it rotates the rectangle and everything keeping the resizing working but the text dissappears when it is rotated, so ya...

PS: The circle rotation code is a bit shorter, and on the bottom...
</prePostEdit>

So, when is the next challenege?

Enjoy smile.gif

CODE
var dragging = 0;
var corner = 0;
var select;
function render(x, y, tx, ty){
    var holder:MovieClip = _root.createEmptyMovieClip("holder", 0);
        holder._x = x;
        holder._y = y;
    var bg:MovieClip = holder.createEmptyMovieClip("bg", 0);
    var top:MovieClip = holder.createEmptyMovieClip("top", 1);
    var right:MovieClip = holder.createEmptyMovieClip("right", 2);
        right._x = tx-holder._x;
    var bottom:MovieClip = holder.createEmptyMovieClip("bottom", 3);
        bottom._y = ty-holder._y;
    var left:MovieClip = holder.createEmptyMovieClip("left", 4);
    var tTop:TextField = holder.createTextField("tTop", 5, 80, -20, 24, 20);
        tTop.text = "200";
        tTop.autoSize;
        tTop._x = (200-tTop._width)/2;
        tTop._y = -tTop._height;
    var tRight:TextField = holder.createTextField("tRight", 6, 200, 40, 24, 20);
        tRight.text = "100";
        tRight.autoSize;
        tRight._x = right._x;
        tRight._y = (100-tRight._height)/2;
    var trc:MovieClip = holder.createEmptyMovieClip("topRightCircle", 7);
    var tlc:MovieClip = holder.createEmptyMovieClip("topLeftCircle", 8);
    var brc:MovieClip = holder.createEmptyMovieClip("bottomRightCircle", 9);
    var blc:MovieClip = holder.createEmptyMovieClip("bottomLeftCircle", 10);
    
    createCircle(tlc, 4, 0, 0, 0x00000000);
    createCircle(trc, 4, 0, 0, 0x00000000);
    createCircle(blc, 4, 0, 0, 0x00000000);
    createCircle(brc, 4, 0, 0, 0x00000000);
    brc._x = trc._x = 200;
    brc._y = blc._y = 100;
    
    createFill(bg, (tx-x), (ty-y), 1, 0x00000099, "Gradient", [0x00ccccff, 0x00666699]);
    createFill(top, 200, 1, 2, 0x00000099, "None");
    createFill(right, 1, 100, 2, 0x00000099, "None");
    createFill(bottom, 200, 1, 2, 0x00000099, "None");
    createFill(left, 1, 100, 2, 0x00000099, "None");
    
    holder.onMouseMove = function(){
        if(dragging == 1){
            if(corner == 1){
                if(select == tlc){
                    left._x = tlc._x;
                    top._y = tlc._y;
                }
                else if(select == trc){
                    right._x = trc._x;
                    top._y = trc._y;
                }
                else if(select == blc){
                    left._x = blc._x;
                    bottom._y = blc._y;
                }
                else if(select == brc){
                    right._x = brc._x;
                    bottom._y = brc._y;
                }
            }
            
            if(left._x<0 && left._x<right._x){
                top._x = bottom._x = left._x;
                bg._width = -left._x+right._x+2;
                top._width = bottom._width = bg._width;
                bg._x = left._x;
                tRight._x = right._x;
                blc._x = tlc._x = left._x;
                brc._x = trc._x = right._x;
            }
            else if(left._x>0 && left._x<right._x){
                top._x = bottom._x = left._x;
                bg._width = right._x-left._x+2;
                top._width = bottom._width = bg._width;
                bg._x = left._x;
                tRight._x = right._x;
                blc._x = tlc._x = left._x;
                brc._x = trc._x = right._x;
            }
            else if(left._x>right._x){
                bg._width = left._x-right._x+2;
                top._width = bottom._width = bg._width;
                bg._x = left._x-bg._width;
                top._x = bottom._x = bg._x;
                tRight._x = left._x;
                blc._x = tlc._x = left._x;
                brc._x = trc._x = right._x;
            }
            else if(left._x<right._x){
                top._x = bottom._x = left._x;
                bg._width = -left._x+right._x+2;
                top._width = bottom._width = bg._width;
                bg._x = left._x;
                tRight._x = right._x;
                blc._x = tlc._x = left._x;
                brc._x = trc._x = right._x;
            }
            
            if(top._y<0 && top._y<bottom._y){
                left._y = right._y = top._y;
                bg._height = -top._y+bottom._y+2;
                left._height = right._height = bg._height;
                bg._y = top._y;
                tTop._y = top._y-tTop._height;
                tlc._y = trc._y = top._y;
                blc._y = brc._y = bottom._y;
            }
            else if(top._y>0 && top._y<bottom._y){
                left._y = right._y = top._y;
                bg._height = bottom._y-top._y+2;
                left._height = right._height = bg._height;
                bg._y = top._y;
                tTop._y = top._y-tTop._height;
                tlc._y = trc._y = top._y;
                blc._y = brc._y = bottom._y;
            }
            else if(top._y>bottom._y){
                bg._height = top._y-bottom._y+2;
                left._height = right._height = bg._height;
                bg._y = top._y-bg._height;
                left._y = right._y = bottom._y;
                tTop._y = bottom._y-tTop._height;
                tlc._y = trc._y = top._y;
                blc._y = brc._y = bottom._y;
            }
            else if(top._y<bottom._y){
                left._y = right._y = top._y;
                bg._height = -top._y+bottom._y+2;
                left._height = right._height = bg._height;
                bg._y = top._y;
                tTop._y = top._y-tTop._height;
                tlc._y = trc._y = top._y;
                blc._y = brc._y = bottom._y;
            }
            
            tRight.text = ""+bg._height;
            tRight._y = bg._y+((bg._height-tRight._height)/2);
            tTop.text = ""+bg._width;
            tTop._x = bg._x+((bg._width-tTop._width)/2);
        }
    }
    
    blc.onPress = brc.onPress = trc.onPress = tlc.onPress = function(){
        select = this;
        dragging = 1;
        corner = 1;
        this.startDrag();
    }
    blc.onRelease = blc.onReleaseOutside = brc.onRelease = brc.onReleaseOutside = trc.onRelease = trc.onReleaseOutside = tlc.onRelease = tlc.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        corner = 0;
    }
    
    top.onRollOver = function(){
        createFill(this, 200, 1, 2, 0x00990000, "None");
    }
    top.onRollOut = function(){
        createFill(this, 200, 1, 2, 0x00000099, "None");
    }
    top.onPress = function(){
        createFill(this, 200, 1, 3, 0x00009900, "None");
        this.startDrag(false, this._x, Stage.height, 0, -Stage.height);
        dragging = 1;
    }
    top.onRelease = top.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        this.onRollOut();
    }
    bottom.onRollOver = function(){
        createFill(this, 200, 1, 2, 0x00990000, "None");
    }
    bottom.onRollOut = function(){
        createFill(this, 200, 1, 2, 0x00000099, "None");
    }
    bottom.onPress = function(){
        createFill(this, 200, 1, 3, 0x00009900, "None");
        this.startDrag(false, this._x, Stage.height, 0, -Stage.height);
        dragging = 1;
    }
    bottom.onRelease = bottom.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        this.onRollOut();
    }
    left.onRollOver = function(){
        createFill(this, 1, 100, 2, 0x00990000, "None");
    }
    left.onRollOut = function(){
        createFill(this, 1, 100, 2, 0x00000099, "None");
    }
    left.onPress = function(){
        createFill(this, 1, 100, 3, 0x00009900, "None");
        this.startDrag(false, -Stage.width, this._y, Stage.width, 0);
        dragging = 1;
    }
    left.onRelease = left.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        this.onRollOut();
    }
    right.onRollOver = function(){
        createFill(this, 1, 100, 2, 0x00990000, "None");
    }
    right.onRollOut = function(){
        createFill(this, 1, 100, 2, 0x00000099, "None");
    }
    right.onPress = function(){
        createFill(this, 1, 100, 3, 0x00009900, "None");
        this.startDrag(false, -Stage.width, this._y, Stage.width, 0);
        dragging = 1;
    }
    right.onRelease = right.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        this.onRollOut();
    }
}
render((Stage.width-200)/2, (Stage.height-100)/2, ((Stage.width-200)/2)+200, ((Stage.height-100)/2)+100);

function createFill(obj:MovieClip, w, h, border, borderColor, bgStyle, bgColors){
    obj.lineStyle(border, borderColor, 100);
    if(bgStyle == "Gradient"){
        alphas = [100, 100];
        ratios = [0, h*1.5];
        matrix = {matrixType:"box", x:0, y:0, w:430, h:150, r:Math.PI/2};
        obj.beginGradientFill("linear", bgColors, alphas, ratios, matrix);
    }
    else if(bgStyle == "Solid"){
        obj.beginFill(bgColors[0], 100);
    }
    obj.lineTo(w, 0);
    obj.lineTo(w, h);
    obj.lineTo(0, h);
    obj.lineTo(0, 0);
    if(bgStyle != "None"){
        obj.endFill();
    }
}

function createCircle(obj, r, x, y, bgColor){
    obj.beginFill(bgColor, 100);
    obj.moveTo(x+r, y);
    A = Math.tan(22.5 * Math.PI/180);
    for (angle = 45; angle<=360; angle += 45) {
        endx = r*Math.cos(angle*Math.PI/180);
        endy = r*Math.sin(angle*Math.PI/180);
        cx =endx + r* A *Math.cos((angle-90)*Math.PI/180);
        cy =endy + r* A *Math.sin((angle-90)*Math.PI/180);
        obj.curveTo(cx+x, cy+y, endx+x, endy+y);
    }
}


Circle Rotation Code:
CODE
var dragging = 0;
var corner = 0;
var pos;
function render(x, y, tx, ty){
    var holder:MovieClip = _root.createEmptyMovieClip("holder", 0);
        holder._x = x;
        holder._y = y;
    var bg:MovieClip = holder.createEmptyMovieClip("bg", 0);
    var top:MovieClip = holder.createEmptyMovieClip("top", 1);
    var right:MovieClip = holder.createEmptyMovieClip("right", 2);
        right._x = tx-holder._x;
    var bottom:MovieClip = holder.createEmptyMovieClip("bottom", 3);
        bottom._y = ty-holder._y;
    var left:MovieClip = holder.createEmptyMovieClip("left", 4);
    var tTop:TextField = holder.createTextField("tTop", 5, 80, -20, 24, 20);
        tTop.text = "200";
        tTop.autoSize;
        tTop._x = (200-tTop._width)/2;
        tTop._y = -tTop._height;
        tTop._accProps;
    var tRight:TextField = holder.createTextField("tRight", 6, 200, 40, 24, 20);
        tRight.text = "100";
        tRight.autoSize;
        tRight._x = right._x;
        tRight._y = (100-tRight._height)/2;
    var trc:MovieClip = holder.createEmptyMovieClip("topRightCircle", 7);
    var tlc:MovieClip = holder.createEmptyMovieClip("topLeftCircle", 8);
    var brc:MovieClip = holder.createEmptyMovieClip("bottomRightCircle", 9);
    var blc:MovieClip = holder.createEmptyMovieClip("bottomLeftCircle", 10);
    
    createCircle(tlc, 4, 0, 0, 0x00000000);
    createCircle(trc, 4, 0, 0, 0x00000000);
    createCircle(blc, 4, 0, 0, 0x00000000);
    createCircle(brc, 4, 0, 0, 0x00000000);
    brc._x = trc._x = 200;
    brc._y = blc._y = 100;
    
    createFill(bg, (tx-x), (ty-y), 1, 0x00000099, "Gradient", [0x00ccccff, 0x00666699]);
    createFill(top, 200, 1, 2, 0x00000099, "None");
    createFill(right, 1, 100, 2, 0x00000099, "None");
    createFill(bottom, 200, 1, 2, 0x00000099, "None");
    createFill(left, 1, 100, 2, 0x00000099, "None");
    
    holder.onMouseMove = function(){
        if(corner == 1){
            
            adjside =_root. _xmouse-pos[0];
            oppside = -1*(_root._ymouse-pos[1]);
            angle = Math.atan2(oppside, adjside);
            angle = Math.round(angle/Math.PI*180);
            holder._rotation = -angle;
            
        }
        if(dragging == 1){
            if(left._x<0 && left._x<right._x){
                top._x = bottom._x = left._x;
                bg._width = -left._x+right._x+2;
                top._width = bottom._width = bg._width;
                bg._x = left._x;
                tRight._x = right._x;
                blc._x = tlc._x = left._x;
                brc._x = trc._x = right._x;
            }
            else if(left._x>0 && left._x<right._x){
                top._x = bottom._x = left._x;
                bg._width = right._x-left._x+2;
                top._width = bottom._width = bg._width;
                bg._x = left._x;
                tRight._x = right._x;
                blc._x = tlc._x = left._x;
                brc._x = trc._x = right._x;
            }
            else if(left._x>right._x){
                bg._width = left._x-right._x+2;
                top._width = bottom._width = bg._width;
                bg._x = left._x-bg._width;
                top._x = bottom._x = bg._x;
                tRight._x = left._x;
                blc._x = tlc._x = left._x;
                brc._x = trc._x = right._x;
            }
            else if(left._x<right._x){
                top._x = bottom._x = left._x;
                bg._width = -left._x+right._x+2;
                top._width = bottom._width = bg._width;
                bg._x = left._x;
                tRight._x = right._x;
                blc._x = tlc._x = left._x;
                brc._x = trc._x = right._x;
            }
            
            if(top._y<0 && top._y<bottom._y){
                left._y = right._y = top._y;
                bg._height = -top._y+bottom._y+2;
                left._height = right._height = bg._height;
                bg._y = top._y;
                tTop._y = top._y-tTop._height;
                tlc._y = trc._y = top._y;
                blc._y = brc._y = bottom._y;
            }
            else if(top._y>0 && top._y<bottom._y){
                left._y = right._y = top._y;
                bg._height = bottom._y-top._y+2;
                left._height = right._height = bg._height;
                bg._y = top._y;
                tTop._y = top._y-tTop._height;
                tlc._y = trc._y = top._y;
                blc._y = brc._y = bottom._y;
            }
            else if(top._y>bottom._y){
                bg._height = top._y-bottom._y+2;
                left._height = right._height = bg._height;
                bg._y = top._y-bg._height;
                left._y = right._y = bottom._y;
                tTop._y = bottom._y-tTop._height;
                tlc._y = trc._y = top._y;

                blc._y = brc._y = bottom._y;
            }
            else if(top._y<bottom._y){
                left._y = right._y = top._y;
                bg._height = -top._y+bottom._y+2;
                left._height = right._height = bg._height;
                bg._y = top._y;
                tTop._y = top._y-tTop._height;
                tlc._y = trc._y = top._y;
                blc._y = brc._y = bottom._y;
            }
            
            tRight.text = ""+bg._height;
            tRight._y = bg._y+((bg._height-tRight._height)/2);
            tTop.text = ""+bg._width;
            tTop._x = bg._x+((bg._width-tTop._width)/2);
        }
    }
    
    blc.onPress = brc.onPress = trc.onPress = tlc.onPress = function(){
        pos = [_root._xmouse, _root._ymouse];
        corner = 1;
        this.startDrag(false, this._x, this._y, this._x, this._y);
    }
    blc.onRelease = blc.onReleaseOutside = brc.onRelease = brc.onReleaseOutside = trc.onRelease = trc.onReleaseOutside = tlc.onRelease = tlc.onReleaseOutside = function(){
        this.stopDrag();
        corner = 0;
    }
    
    top.onRollOver = function(){
        createFill(this, 200, 1, 2, 0x00990000, "None");
    }
    top.onRollOut = function(){
        createFill(this, 200, 1, 2, 0x00000099, "None");
    }
    top.onPress = function(){
        createFill(this, 200, 1, 3, 0x00009900, "None");
        this.startDrag(false, this._x, Stage.height, 0, -Stage.height);
        dragging = 1;
    }
    top.onRelease = top.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        this.onRollOut();
    }
    bottom.onRollOver = function(){
        createFill(this, 200, 1, 2, 0x00990000, "None");
    }
    bottom.onRollOut = function(){
        createFill(this, 200, 1, 2, 0x00000099, "None");
    }
    bottom.onPress = function(){
        createFill(this, 200, 1, 3, 0x00009900, "None");
        this.startDrag(false, this._x, Stage.height, 0, -Stage.height);
        dragging = 1;
    }
    bottom.onRelease = bottom.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        this.onRollOut();
    }
    left.onRollOver = function(){
        createFill(this, 1, 100, 2, 0x00990000, "None");
    }
    left.onRollOut = function(){
        createFill(this, 1, 100, 2, 0x00000099, "None");
    }
    left.onPress = function(){
        createFill(this, 1, 100, 3, 0x00009900, "None");
        this.startDrag(false, -Stage.width, this._y, Stage.width, 0);
        dragging = 1;
    }
    left.onRelease = left.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        this.onRollOut();
    }
    right.onRollOver = function(){
        createFill(this, 1, 100, 2, 0x00990000, "None");
    }
    right.onRollOut = function(){
        createFill(this, 1, 100, 2, 0x00000099, "None");
    }
    right.onPress = function(){
        createFill(this, 1, 100, 3, 0x00009900, "None");
        this.startDrag(false, -Stage.width, this._y, Stage.width, 0);
        dragging = 1;
    }
    right.onRelease = right.onReleaseOutside = function(){
        this.stopDrag();
        dragging = 0;
        this.onRollOut();
    }
}
render((Stage.width-200)/2, (Stage.height-100)/2, ((Stage.width-200)/2)+200, ((Stage.height-100)/2)+100);

function createFill(obj:MovieClip, w, h, border, borderColor, bgStyle, bgColors){
    obj.lineStyle(border, borderColor, 100);
    if(bgStyle == "Gradient"){
        alphas = [100, 100];
        ratios = [0, h*1.5];
        matrix = {matrixType:"box", x:0, y:0, w:430, h:150, r:Math.PI/2};
        obj.beginGradientFill("linear", bgColors, alphas, ratios, matrix);
    }
    else if(bgStyle == "Solid"){
        obj.beginFill(bgColors[0], 100);
    }
    obj.lineTo(w, 0);
    obj.lineTo(w, h);
    obj.lineTo(0, h);
    obj.lineTo(0, 0);
    if(bgStyle != "None"){
        obj.endFill();
    }
}

function createCircle(obj, r, x, y, bgColor){
    obj.beginFill(bgColor, 100);
    obj.moveTo(x+r, y);
    A = Math.tan(22.5 * Math.PI/180);
    for (angle = 45; angle<=360; angle += 45) {
        endx = r*Math.cos(angle*Math.PI/180);
        endy = r*Math.sin(angle*Math.PI/180);
        cx =endx + r* A *Math.cos((angle-90)*Math.PI/180);
        cy =endy + r* A *Math.sin((angle-90)*Math.PI/180);
        obj.curveTo(cx+x, cy+y, endx+x, endy+y);
    }
}


Well, there we go. Time to post! (Only 2:56 AM here...)
User is offlineProfile CardPM
+Quote Post

skater_00
RE: Flash Challenge #1 - A Rectangle
16 Oct, 2008 - 07:47 PM
Post #20

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 236



Thanked: 9 times
Dream Kudos: 250
My Contributions
lol, what's the point in ActionScript challenges when people post their solutions in public and ruin the challenge for everyone else? tongue.gif Doesn't make much sense to me..
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 11:29AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month