A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Breaking up compound words

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    4

    Post Breaking up compound words

    Hi,
    I'm working on a page for the Interactive 'SmartBoard'. As part of a lesson in teaching compound words the students have to break up a compound word into its two smaller words. I envisage dragging a perpendicular bar and dropping it between the two words. If placed correctly the two words will separate slightly indicating that the answer is correct. If the bar is placed in the wrong position then nothing happens. I have given this a lot of thought and searched the net but don't know where to start. Any help with this would be most appreciated. I'm using CS5.5

    Bruce

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Maybe try something like this..
    Code:
    package {
    	import flash.display.*;
    	import flash.events.*;
    
    	public class BreakerBar extends MovieClip {
    
    		public function BreakerBar() {
    			addEventListener(Event.REMOVED_FROM_STAGE,removeListeners);
    			addEventListener(Event.ADDED_TO_STAGE, init);
    		}
    		private function init($e:Event):void {
    			removeEventListener(Event.ADDED_TO_STAGE, init);
    			addEventListener(MouseEvent.MOUSE_DOWN, begDrag, false, 0, true);
    		}
    		private function begDrag($e:Event):void {
    			startDrag();
    			this.parent.setChildIndex(this, this.parent.numChildren - 1);
    			stage.addEventListener(MouseEvent.MOUSE_UP, endDrag, false, 0, true);
    		}
    		private function endDrag($e:Event):void {
    			stopDrag();
    			stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag);
    		}
    		private function removeListeners($e:Event):void {
    			removeEventListener(Event.REMOVED_FROM_STAGE,removeListeners);
    			stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag);
    			removeEventListener(MouseEvent.MOUSE_DOWN, begDrag)
    		}
    	}
    }
    Code:
    package {
    	import flash.display.*;
    	import flash.events.*;
    	import flash.text.*;
    	import flash.geom.*;
    	import flash.utils.*;
    	import fl.motion.easing.Back;
    
    	public class CompoundWord extends MovieClip {
    		private const SPACER:String = "     ";
    		private var _txt:TextField;
    		private var _pos:int;
    		private var _isRight:Boolean = false;
    
    		public function CompoundWord() {
    			addEventListener(Event.REMOVED_FROM_STAGE,removeListeners);
    			addEventListener(Event.ADDED_TO_STAGE, init);
    		}
    		private function init($e:Event):void {
    			removeEventListener(Event.ADDED_TO_STAGE, init);
    			var format:TextFormat = new TextFormat();
    			format.letterSpacing = 0;
    			format.size = 40;
    			format.bold = true;
    			_txt = new TextField();
    			_txt.selectable = false;
    			_txt.autoSize = TextFieldAutoSize.LEFT;
    			_txt.defaultTextFormat = format;
    			_pos = this.name.indexOf("_");
    			var named:String = this.name.split("_").join("");
    			_txt.text = named;
    			addChild(_txt);
    			stage.addEventListener(MouseEvent.MOUSE_UP, selectText);
    		}
    		private function selectText(event:MouseEvent):void {
    			if (getQualifiedClassName(event.target) == "BreakerBar" && !_isRight) {
    				var clicked_on_index:int = _txt.getCharIndexAtPoint(_txt.mouseX,_txt.mouseY);
    				//var clicked_on_char:String = _txt.text.substr(clicked_on_index,1);
    				if (clicked_on_index != -1) {
    					var rect:Rectangle = _txt.getCharBoundaries(clicked_on_index);
    					if (rect.x + (rect.width * 0.5) > _txt.mouseX) {
    						clicked_on_index -=  1;
    					}
    					if (_pos == clicked_on_index + 1) {
    						var named:String = this.name.split("_").join(SPACER);
    						_txt.x -= 20;
    						_txt.text = named;
    						_isRight = true;
    					}
    				}
    			}
    		}
    		private function removeListeners($e:Event):void {
    			removeEventListener(Event.REMOVED_FROM_STAGE,removeListeners);
    			stage.removeEventListener(MouseEvent.MOUSE_UP, selectText);
    		}
    	}
    }
    To try this...
    Create breakerBar movieclip with your dividing line, set to export in frame 1, Class: BreakerBar then add it to the stage.
    Create an empty clip, named coumpoundWord, set to export in frame 1, Class: CompoundWord.
    Drag instance to stage, give instance name "ROW_BOAT".
    Create as many instances on stage as you need, making sure that each instance name has an underscore "_" where you want to split the word.
    Run program.

    HTH

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    4
    Hi Dawsonk,
    Thanks so much for you detailed response with accompanying AS. Sorry about the delay in replying but I found the notification email from flashkit in my spam folder which I don't check all that often. I'll be getting back onto this over the weekend! Much appreciated!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center