I'm brand new to OOP - I've been watching iTunes U videos and reading books but it's still all pretty abstract in my mind and it's difficult for me to pin point how all that stuff translates to actually writing good code.
Basically, it's an open ended kid's dictionary. You drag the lettes to drop boxes, touch the check to see if it's a word, and then a picture representing the word pops up on the screen.
All of it works except if you try to remove a letter that's already been placed. Originally, I wanted the check button to do a sweep of the dropped letters and see if they had formed a word - but I couldn't figure out a way to do that. So then I started tracking movements of letters in real time, and that's when it got really confusing. I think I just need to start over and try to make the code a bit cleaner. Right now this is what I've got:
if (currentUsedBlank is BlankSquare) { //if they have removed a letter that has already been dropped if (currentUsedBlank != currentBlank) { //and it's been placed back on a different square currentUsedBlank.letter = null; } } else { currentUsedBlank.letter = null; } if (this.dropTarget.parent is BlankSquare && currentBlank.letter == null) { SpellingGlobals.lettersInBlanks[SpellingGlobals.lettersInBlanks.length] = this; this.x = this.dropTarget.parent.x + 10; this.y = this.dropTarget.parent.y - 10; var myClass:Class = getDefinitionByName(getQualifiedClassName(MovieClip(this))) as Class; var newLetter:MovieClip = new myClass(); newLetter.x = currentLetter.startPoint.x; newLetter.y = currentLetter.startPoint.y; newLetter.letter = currentLetter.letter; newLetter.reference = currentLetter.reference; newLetter.startPoint.x = currentLetter.startPoint.x; newLetter.startPoint.y = currentLetter.startPoint.y; newLetter.isVowel = currentLetter.isVowel; currentBlank.letter = currentLetter.letter; if (SpellingGlobals.isCaps == true) { newLetter.txt.text.toUpperCase(); if (SpellingGlobals.isColor == true) { if (newLetter.isVowel) { newLetter.txt.textColor = SpellingGlobals.colorVowel; } else { newLetter.txt.textColor = SpellingGlobals.colorCon; } } } MovieClip(root).addChild(newLetter); SpellingGlobals.copiedLetters[SpellingGlobals.copiedLetters.length] = newLetter; currentBlank.alpha = 0; } else { this.x = MovieClip(this).startPoint.x; this.y = MovieClip(this).startPoint.y; } this.stopDrag(); }
|
I feel you are overcomplicating things
How I'd do is to have two classes: Letter class and (for want of a better word) Word class, both extends Sprite.
Letter class dispatches events on mouse press (start drag) and on mouse release (stop drag).
Word class listens to above events. On release (drop) event, if the Letter is dropped in one of its empty slots populate the array of letters. On press event (pick up = start drag) if the Letter was in one of the slots remove it from the array of letters.
When the "look up" button is pressed you use the array of letters in the Word class to see if it forms a word. Simple 