flash on 2011-10-3

by fujiopera
The following code is example code from 
"ActionScript 3.0 Bible, 2nd Edition" by Roger Braunstein
Find all of the source code on the companion website
http://actionscriptbible.com/

Copyright (c) 2010 by Wiley Publishing, Inc., Indianapolis, Indiana

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
N
♥0 | Line 64 | Modified 2011-10-03 11:06:58 | MIT License
play

ActionScript3 source code

/**
 * Copyright fujiopera ( http://wonderfl.net/user/fujiopera )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4jRm
 */

// The following code is example code from 
// "ActionScript 3.0 Bible, 2nd Edition" by Roger Braunstein
// Find all of the source code on the companion website
// http://actionscriptbible.com/
//
// Copyright (c) 2010 by Wiley Publishing, Inc., Indianapolis, Indiana
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

package {
  import flash.display.Sprite;
  import flash.events.*;
  import flash.net.*;
  import flash.text.*;
  public class ch30ex3 extends Sprite {
    protected var fileRef:FileReference;
    protected var button:TestButton;
    protected var tf:TextField;
    public function ch30ex3() {
      button = new TestButton(100, 25, "Gimme");
      button.addEventListener(MouseEvent.CLICK, onGimme);
      button.x = 330; button.y = 20;
      addChild(button);
      
      tf = new TextField();
      tf.type = TextFieldType.INPUT;
      tf.defaultTextFormat = new TextFormat("_sans", 12, 0);
      tf.multiline = tf.wordWrap = false; 
      tf.border = true;
      tf.width = 300; tf.height = 24; tf.x = 20; tf.y = 20;
      addChild(tf);
      tf.text = "TYPE HERE.";
    }
    protected function onGimme(event:MouseEvent):void {
      fileRef = new FileReference();
      //uses ENfer, a Smeltery free font - http://www.smeltery.net
      var URL:String = "http://actionscriptbible.com/files/text.php";
      var urlReq:URLRequest = new URLRequest(URL);
      urlReq.data = new URLVariables();
      urlReq.data.text = tf.text;
      fileRef.download(urlReq, "Your Dang Hot Pink Text.png");
      fileRef.addEventListener(Event.CANCEL, onReset);
      fileRef.addEventListener(Event.COMPLETE, onReset);
      
      button.mouseEnabled = button.tabEnabled = false;
      button.alpha = 0.5;
    }
    protected function onReset(event:Event):void {
      fileRef.removeEventListener(Event.CANCEL, onReset);
      fileRef.removeEventListener(Event.COMPLETE, onReset);
      
      tf.text = "";
      button.mouseEnabled = button.tabEnabled = true;
      button.alpha = 1;
    }
  }
}
import flash.display.*;
import flash.text.*;
class TestButton extends Sprite {
  public var label:TextField;
  public function TestButton(w:Number, h:Number, labelText:String) {
    graphics.lineStyle(0.5, 0, 0, true);
    graphics.beginFill(0xa0a0a0);
    graphics.drawRoundRect(0, 0, w, h, 8);
    label = new TextField();
    addChild(label);
    label.defaultTextFormat = new TextFormat("_sans", 11, 0, true, false,
      false, null, null, "center");
    label.width = w;
    label.height = h;
    label.text = labelText;
    label.y = (h - label.textHeight)/2 - 2;
    buttonMode = true;
    mouseChildren = false;
  }
}