Commit f95c43ec authored by O'Reilly Media, Inc's avatar O'Reilly Media, Inc

Initial commit

parents
## Example files for the title:
# Learning ActionScript 3.0 2nd Edition, by Rich Shupe
[![Learning ActionScript 3.0 2nd Edition, by Rich Shupe](http://akamaicovers.oreilly.com/images/9781449390174/cat.gif)](https://www.safaribooksonline.com/library/view/title/9781449398705//)
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
package { import flash.display.MovieClip; public class Main extends MovieClip { public function Main() { trace("Flash"); } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.text.TextField; public class HelloWorld extends MovieClip { public function HelloWorld() { var txtFld:TextField = new TextField(); addChild(txtFld); txtFld.text = "Hello World!"; } }}
\ No newline at end of file
package { public class Car extends Vehicle { public var tires:Tires; public function Car(mpg:Number, fuel:Number) { gasMileage = mpg; fuelAvailable = fuel; tires = new Tires("highperformance"); trace(this, "has", tires.type, "tires"); } public function openSunroof () { trace(this, "opened sunroof"); } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; public class Main extends MovieClip { public var compact:Car; public var pickup:Truck; public function Main() { compact = new Car(21, 18); compact.x = 20; compact.y = 20; addChild(compact); compact.openSunroof(); pickup = new Truck(16, 23); pickup.x = 20; pickup.y = 100; addChild(pickup); pickup.lowerTailgate(); this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); } public function onAddedToStage(evt:Event):void { this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); stage.addEventListener(MouseEvent.CLICK, onClick, false, 0, true); } public function onClick(evt:MouseEvent):void { compact.go(); pickup.go(); } } }
\ No newline at end of file
package { public class Tires { public var type:String; public function Tires(tire:String) { //simulated functionality change based on tire type switch (tire) { case "snow" : type = "storm-ready snow"; break; case "highperformance" : type = "high-performance radial"; break; default : type = "economical bias-ply"; break; } } } }
\ No newline at end of file
package { public class Truck extends Vehicle { public var tires:Tires; public function Truck(mpg:Number, fuel:Number) { gasMileage = mpg; fuelAvailable = fuel; tires = new Tires("snow"); trace(this, "has", tires.type, "tires"); } public function lowerTailgate () { trace(this, "lowered tailgate"); } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.events.Event; public class Vehicle extends MovieClip { public var gasMileage:Number; public var fuelAvailable:Number; public var milesTraveled:Number = 0; public var moving:Boolean; public function Vehicle(mpg:Number=21, fuel:Number=18.5) { gasMileage = mpg; fuelAvailable = fuel; this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true); } public function onLoop(evt:Event):void { if (moving) { fuelAvailable--; milesTraveled += gasMileage; if (fuelAvailable < 1) { this.removeEventListener(Event.ENTER_FRAME, onLoop); } trace(this, milesTraveled, fuelAvailable); this.x = milesTraveled; } } public function go():void { moving = true; } }}
\ No newline at end of file
package { import flash.display.MovieClip; public class Main extends MovieClip{ public function Main() { trace("Flash"); } }}
\ No newline at end of file
package { public class Car extends Vehicle { private var _tires:Tires; public function Car(mpg:Number, fuel:Number) { super(mpg, fuel); _tires = new Tires("highperformance"); trace(this, "has", _tires.type, "tires"); } public function openSunroof () { trace(this, "opened sunroof"); } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; public class Main extends MovieClip { private var _compact:Car; private var _pickup:Truck; public function Main() { _compact = new Car(21, 18); _compact.x = 0; _compact.y = 20; addChild(_compact); _compact.openSunroof(); _pickup = new Truck(16, 23); _pickup.x = 0; _pickup.y = 100; addChild(_pickup); _pickup.lowerTailgate(); this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); } private function onClick(evt:MouseEvent):void { _compact.go(); _pickup.go(); } private function onAddedToStage(evt:Event):void { this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); stage.addEventListener(MouseEvent.CLICK, onClick, false, 0, true); } }}
\ No newline at end of file
package { public class Tires { private var _type:String; public function Tires(tire:String) { //simulated functionality change based on tire type switch (tire) { case "snow" : _type = "storm-ready snow"; break; case "highperformance" : _type = "high-performance radial"; break; default : _type = "economical bias-ply"; } } public function get type():String { return _type; } public function set type(tire:String):void { _type = tire; } } }
\ No newline at end of file
package { public class Truck extends Vehicle { private var _tires:Tires; public function Truck(mpg:Number, fuel:Number) { super(mpg, fuel); _tires = new Tires("snow"); trace(this, "has", _tires.type, "tires"); } public function lowerTailgate () { trace(this, "lowered tailgate"); } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.events.Event; public class Vehicle extends MovieClip { private var _gasMileage:Number; private var _fuelAvailable:Number; private var _milesTraveled:Number = 0; private var _moving:Boolean; public function Vehicle(mpg:Number=21, fuel:Number=18.5) { _gasMileage = mpg; _fuelAvailable = fuel; this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true); } private function onLoop(evt:Event):void { if (_moving) { _fuelAvailable--; _milesTraveled += _gasMileage; if (_fuelAvailable < 1) { this.removeEventListener(Event.ENTER_FRAME, onLoop); } trace(this, _milesTraveled, _fuelAvailable); this.x = _milesTraveled; } } public function go():void { _moving = true; } //new getters and setters public function get gasMileage():Number { return _gasMileage; } public function set gasMileage(mpg:Number):void { _gasMileage = mpg; } public function get fuelAvailable():Number { return _fuelAvailable; } public function set fuelAvailable(fuel:Number):void { _fuelAvailable = fuel; } public function get milesTraveled():Number { return _milesTraveled; } } }
\ No newline at end of file
package { public class Car extends Vehicle { public function Car(mpg:Number, fuel:Number) { gasMileage = mpg; fuelAvailable = fuel; } public function openSunroof () { trace(this, "opened sunroof"); } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; public class Main extends MovieClip { public var compact:Car; public var pickup:Truck; public function Main() { compact = new Car(21, 18); compact.x = 0; compact.y = 20; addChild(compact); compact.openSunroof(); pickup = new Truck(16, 23); pickup.x = 0; pickup.y = 100; addChild(pickup); pickup.lowerTailgate(); this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); } public function onAddedToStage(evt:Event):void { this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); stage.addEventListener(MouseEvent.CLICK, onClick, false, 0, true); } public function onClick(evt:MouseEvent):void { compact.go(); pickup.go(); } }}
\ No newline at end of file
package { public class Truck extends Vehicle { public function Truck(mpg:Number, fuel:Number) { gasMileage = mpg; fuelAvailable = fuel; } public function lowerTailgate () { trace(this, "lowered tailgate"); } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.events.Event; public class Vehicle extends MovieClip { public var gasMileage:Number; public var fuelAvailable:Number; public var milesTraveled:Number = 0; public var moving:Boolean; public function Vehicle(mpg:Number=21, fuel:Number=18.5) { gasMileage = mpg; fuelAvailable = fuel; this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true); } private function onLoop(evt:Event):void { if (moving) { fuelAvailable--; milesTraveled += gasMileage; if (fuelAvailable < 1) { this.removeEventListener(Event.ENTER_FRAME, onLoop); } trace(this, milesTraveled, fuelAvailable); this.x = milesTraveled; } } public function go():void { moving = true; } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.display.Graphics; import flash.events.Event; public class Box extends MovieClip { public var color:uint = 0x000099; public function Box() { this.graphics.lineStyle(1, 0x000000); this.graphics.beginFill(color); this.graphics.drawRect(0, 0, 100, 100); this.graphics.endFill(); this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true); } public function onLoop(evt:Event):void { this.x += 5; } }}
\ No newline at end of file
package { import flash.display.MovieClip; import flash.events.Event; public class Square extends MovieClip { public function Square() { this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true); } private function onLoop(evt:Event):void { this.x += 5; } }}
\ No newline at end of file
package { import flash.display.MovieClip; import com.learningactionscript3.gui.NavigationBar; public class LAS3Main extends MovieClip { //public property so it can be accessed from outside the class public var pages:MovieClip; public function LAS3Main() { var appData:Array = ["one", "two", "three", "four", "five"]; var navBar:NavigationBar = new NavigationBar(appData); addChild(navBar); //movie clip in library with linkage class Pages //use addChildAt to add below nav bar pages = new Pages(); pages.y = 100; addChildAt(pages, 0); } } }
\ No newline at end of file
package com.learningactionscript3.gui { import flash.display.MovieClip; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.events.MouseEvent; import app.gui.NavigationBar; public class MenuButtonMain extends MovieClip { private var _btnLabel:TextField; public function MenuButtonMain(labl:String) { _btnLabel = new TextField(); _btnLabel.autoSize = TextFieldAutoSize.CENTER; _btnLabel.textColor = 0xFFFFFF; _btnLabel.text = labl; _btnLabel.mouseEnabled = false; addChild(_btnLabel); buttonMode = true; useHandCursor = true; addEventListener(MouseEvent.CLICK, onClick, false, 0, true); } private function onClick(evt:MouseEvent):void { MovieClip(root.pages).gotoAndStop(_btnLabel.text); //see "_root versus root" in Chapter 4 for more information } } }
\ No newline at end of file
package com.learningactionscript3.gui { import flash.display.MovieClip; public class NavigationBar extends MovieClip { private var _navData:Array; public function NavigationBar(navData:Array) { _navData = navData; build(); } private function build():void { for (var i:int; i < _navData.length; i++) { var menuBtn:MenuButtonMain = new MenuButtonMain(_navData[i]); menuBtn.x = 20 + i * (menuBtn.width + 2); menuBtn.y = 75; addChild(menuBtn); } var hline:MovieClip = new HLineThick(); hline.y = 100; hline.mouseEnabled = false; addChild(hline); } }}
\ No newline at end of file
package { import flash.display.MovieClip; import com.learningactionscript3.gui.NavigationBar; public class LAS3Main extends MovieClip { public function LAS3Main() { var appData:Array = ["one", "two", "three", "four", "five"]; var navBar:NavigationBar = new NavigationBar(appData); addChild(navBar); } }}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.