Download presentation
Presentation is loading. Please wait.
Published byPhillip Griffith Modified over 9 years ago
1
CISC 110 Day 8 “The Outliers, Part 2” Frames, Classes, Vectors, String Manipulation, File I/O, Downloading Images
2
Outline Frame Order Manipulation Creating Classes String Manipulation Drawing with Vectors File Input / Output (I/O) Downloading Images 2
3
Frame Order Manipulation gotoAndStop() gotoAndPlay() play stop currentFrame Example: this.gotoAndPlay(5);
4
Creating Classes package com.example.quickstart { public class Greeter { // ------- Constructor ------- public function Greeter(initialName:String = "") { // set the name value, if specified } // ------- Properties ------- public var name:String; // ------- Methods ------- public function sayHello():String { // create the greeting text and pass it as the return value }
5
Creating Classes import com.example.quickstart.Greeter; // Create a Greeter instance with the initial name "Steve" var myGreeter:Greeter = new Greeter("Steve"); // Say hello to Steve output.text = myGreeter.sayHello(); // Move the cursor to the next line output.text += "\n"; // Set the Greeter instance's name to "Harold" myGreeter.name = "Harold"; // Say hello to Harold output.text += myGreeter.sayHello();
6
Drawing with Vectors The Shape class is used for drawing vector shapes: circles, lines, rectangles The Shape class has a graphics property that is a Graphics object After creating a Shape object, you call its graphic property to access methods of the Graphics class to draw a shape You can’t create a Graphics object directly. Instead create a Shape (or Sprite, …)
7
Drawing a Square var square: Shape = new Shape( ); square.graphics.beginFill( 0x0000ff); // blue square.graphics.lineStyle( 4, 0xff0000 ); // red // Draw a blue square with red border square.graphics.drawRect( 10, 10, 200, 200 ); square.graphics.endFill( ); addChild( square );
8
Drawing Lines var line: Shape = new Shape( ); line.graphics.lineStyle( 6, 0x00ff00 ); line.graphics.moveTo( 130, 140 ); line.graphics.lineTo( 230, 210 ); line.graphics.lineTo( 300, 150 ); line.graphics.lineTo( 30, 240 ); addChild( line );
9
Graphics Class Methods MethodDescription beginFill Specifies fill color and alpha of a shape clear Clears graphics drawn in a Graphics object drawCircle Draws a circle with specified position & radius drawRect Draws a rectangle with specified position, width & height drawRoundRect Same, but also with corner ellipse width and height endFill Applies a fill to all shapes drawn since last call to beginFill lineStyle Specifies border thickness, color, and other options lineTo Draws line from current drawing position to specified position & resets current drawing position moveTo Resets current drawing position to specified position
10
String Manipulation charAt() // select a character within a String substr() // select part of a String in a String search() // check if a String is in a String split() // break a String into an Array join() // merge an Array into a String
11
htmlText textBox.htmlText = “ Go to Google.com ”;
12
File I/O Loading a File (File Input) var myTextLoader:URLLoader = new URLLoader(); myTextLoader.addEventListener(Event.COMPLETE, onLoaded); function onLoaded(e:Event):void { trace(e.target.data); } myTextLoader.load(new URLRequest("example.txt")); //myTextLoader.load(newURLRequest("http://dougwightman.com/cisc110/onlineExample.txt"));http://dougwightman.com/cisc110/onlineExample.txt
13
File I/O Downloading an Image var ldr:Loader = new Loader(); var url:String = "secret.jpg"; /* var url:String = "http://dougwightman.com/cisc110/mystery.jpg";http://dougwightman.com/cisc110/mystery.jpg */ var urlReq:URLRequest = new URLRequest(url); ldr.load(urlReq); addChild(ldr);
14
File I/O Writing a File (File Output) Possible to write to a local or remote (Internet) location Local location: special access privileges required Remote location: special software required –ActionScript + PHP Example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.