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!
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.
Haha, looks-like I'm hijacking this thread 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?
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);
Good one... 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...
.. 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
(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)
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);
var txtFmt:TextFormat = new TextFormat(); txtFmt.align = "center" mcSquare.topWidth_txt.setTextFormat(txtFmt); mcSquare.bottomWidth_txt.setTextFormat(txtFmt);
#1 - You can't have negative lengths 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
Overall, great job.. especially for not using library objects. Two thumbs up.
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.
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" .. . 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.
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.
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.
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.
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;
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
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);
lol, what's the point in ActionScript challenges when people post their solutions in public and ruin the challenge for everyone else? Doesn't make much sense to me..