CISC 110 Day 7 “The Outliers, Part1” hitTest(), Text Input, Frame and Timer Loops, Publishing Flash Content
At this point in the course, you have already seen everything that you need to complete the course project Now we will begin to look at topical features and tools that provide advanced functionality
…Let’s reflect on that for a moment…
Outline keyCode to Character Conversion hitTest() Text Input Frame and Timer Loops Publishing Flash Content –Export to SWF –Export to EXE –Embed in HTML –FTP –Web Hosting 4
keyCode to Character Conversion var e:KeyboardEvent; … trace(e.keyCode); trace(String.fromCharCode(e.charCode)); Output for ‘g’: 71 g
hitTest movieClip1.hitTestObject(movieClip2) Returns “true” if movieClips are overlapping and “false” if they are not.
hitTest …many different hitTests are supported… e.g. myMovieClip.hitTest(x, y, shapeFlag) …check out the API (manual) online!
Input Text Fields How to create using ActionScript: var theTextField:TextField = new TextField(); theTextField.type = TextFieldType.INPUT; theTextField.border = true; theTextField.x = 10; theTextField.y = 10; theTextField.multiline = true; theTextField.wordWrap = true; addChild(theTextField); 8
Input Text Fields Without ActionScript: 1.Create an Input Text box (“Tools” Panel) 2.Assign an Instance Name 3.…now you can access it in ActionScript! 9
TextEvent // Add event listener for any key pressed stage.addEventListener (TextEvent.TEXT_INPUT, readMsg); function readMsg(evt: KeyboardEvent):void { // next line outputs most recent key pressed (as a character) trace(evt.text); } 10
FocusEvent FOCUS_IN occurs when user selects an object letterBox.addEventListener(FocusEvent.FOCUS_IN, blankOutText); function blankOutText(evt:FocusEvent):void { msgBox.text = " "; } 11
FocusEvent FOCUS_OUT occurs when an objects is deselected: i.e. click anywhere outside of the object with mouse letterBox.addEventListener(FocusEvent.FOCUS_OUT, readMsg); function readMsg(evt:FocusEvent):void { trace(msgBox.text); } 12
Frame and Timer Loops Sometimes we want to repeat something while continuing the rest of the animation, e.g., checking if we’ve hit a monster. For this, we can use frame and timer loops. 13
Frame Loop We can create a frame loop by listening for an enter frame event, which is “fired” as each frame is played (i.e. at the same frame rate as the timeline) stage.addEventListener(Event.ENTER_FRAME, fadeMC); function fadeMC(evt: Event):void {if(square.alpha > 0) { square.alpha = square.alpha – 1; } } 14
Timer Loop We can create a timer loop by creating a Timer object, which fires every specified number of ms. var timer: Timer = new Timer(1000); // 1 second timer.addEventListener(TimerEvent.TIMER, fadeMC); timer.start(); function fadeMC(evt: TimerEvent):void {if(square.alpha > 0) { square.alpha = square.alpha – 1; } } 15
Publishing Flash Content Export to SWF Export to EXE (“Create Projector…”) Embed in HTML –File, Publish Preview, HTML –File, Publish Settings –File, Publish
FTP File Transfer Protocol (FTP) –Designed for uploading files to servers
Web Hosting Comes in “all shapes and sizes” –Inexpensive options: Hostrocket.com 1and1.com
USAT