Adobe Animate CC ActionScripts3 error - actionscript-3

I'm trying to using StageWebView in Animate CC 2017, below error show when Test:
"Scene 1, Layer 'Layer 1', Frame 1, Line 1, Column 10 1037: Packages cannot be nested."
Document is empty, in frame 1 i added code.
package {
import flash.display.*;
import flash.geom.Rectangle;
import flash.media.StageWebView;
public class WebView extends Sprite
{
public var webView:StageWebView = new StageWebView();
public function WebView()
{
var htmlString:String = "<!DOCTYPE HTML>" +
"<html><script type=text/javascript>" +
"function callURI(){" +
"alert(\"You clicked me!!\");"+
"}</script><body>" +
"<p><a href=javascript:callURI()>Click Me</a></p>" +
"</body></html>";
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
webView.loadString( htmlString );
}
}
}

Related

How To Load Image Though URL in action script 3.0

I have tested the code in action script 2.0 . it is working great but it does not support GIF so i want it write in action script 3.0.
But i have no idea in this.
var current_loader: Number = 1;
import flash.geom.*;
var current_img: Number = 0;
this.createEmptyMovieClip('img_01', 999);
this.createEmptyMovieClip('img_02', 998);
var loader: MovieClipLoader = new MovieClipLoader();
var listener: Object = new Object();
listener.onLoadComplete = function (target_mc: MovieClip) {
if (target_mc._name == 'img_01') {
img_02._visible = false;
} else {
img_01._visible = false;
}
progress_bar.visible = true;
current_loader.opaqueBackground = 0xFF0000;
};
var interval: Number = setInterval(load_image, 1000);
function load_image() {
loader.addListener(listener);
}
loader.loadClip("http://google/Example3", current_loader);
current_loader = current_loader == 1 ? 2 : 1;
current_img = current_img == images.length - 1 ? 0 : current_img + 1;
}
Very simple in as3:
open Flash IDE, create new .fla file, select first frame, open 'actions (f9)' copy code.
Of course in AS3 it's better to use classes to put your code in.
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.HTTPStatusEvent;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
var imageLoader:Loader = new Loader();
var request:URLRequest = new URLRequest("http://dummyimage.com/600x400/e000e0/fff.gif");
imageLoader.load(request);
addChild (imageLoader);
// and all possible listeners
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
imageLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
imageLoader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
imageLoader.contentLoaderInfo.addEventListener(Event.OPEN, openHandler);
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
function completeHandler(event:Event):void {
trace("completeHandler: " + event);
}
function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
function initHandler(event:Event):void {
trace("initHandler: " + event);
}
function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
function openHandler(event:Event):void {
trace("openHandler: " + event);
}
function progressHandler(event:ProgressEvent):void {
trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}
see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#includeExamplesSummary
There are simpler ways using straight as3 but this a robust way to load may file types with lots of great documentation. https://greensock.com/LoaderMax-AS3
i did like this .And its Working Perfectly.i think it is the simplest .
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
public class Example extends Sprite {
public function Example() {
var myTimer:Timer = new Timer(1000);// 1 second
myTimer.addEventListener(TimerEvent.TIMER,runMany);
myTimer.start();
function runMany(e:TimerEvent):void {
var loader:Loader=new Loader();
var url:String= "http://Google.Example3.com/latimage.php";
loader.load(new URLRequest(url));
addChild(loader);
}
}
}
}

Actionscript Loader Error #1009

I'm trying to make a basic loader that uses Splash.swf to then load myisogame.swf
I keep getting error #1009. It's a template we was given in class, originally the Splash.swf directed to Game.swf, but in the code below there is only one mention of where it directs to.
In the template Game.fla doesn't have any code in it.
Here is the Splash
package {
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
public class Splash extends MovieClip {
var myLoader:Loader;
var loadingAnim:LoadingAnimation;
var percentLoaded:TextField =new TextField();
public function Splash() {
// constructor code
myLoader = new Loader();
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
var blubox = new BluBox();
addChild(blubox);
blubox.x=200;
blubox.y=200;
loadingAnim = new LoadingAnimation();
addChild(loadingAnim);
loadingAnim.x=200;
loadingAnim.y=200;
loadingAnim.scaleX=0;
var format:TextFormat = new TextFormat();
format.font = "Verdana";
format.color = 0xFF0000;
format.size = 20;
format.underline = false;
percentLoaded.defaultTextFormat = format;
addChild(percentLoaded);
percentLoaded.x=200;
percentLoaded.y=230;
myLoader.load(new URLRequest("myisogame.swf"));
}
function onProgress(evt:ProgressEvent):void {
var nPercent:Number = Math.round((evt.bytesLoaded / evt.bytesTotal) * 100);
loadingAnim.scaleX = nPercent / 100;
percentLoaded.text = nPercent.toString() + "%";
trace("load%"+nPercent.toString());
}
function onComplete(evt:Event):void {
myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
myLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
loadingAnim.x=1000;
addChild(myLoader);
}
function onIOError(evt:IOErrorEvent):void {
trace("IOError loading SWF");
}
}
}
5
6
7
8
11
12
13
14
20
25
26
MyIsoGame code
package {
import flash.display.MovieClip;
import as3isolib.display.scene.IsoScene;
import as3isolib.display.IsoView;
import as3isolib.display.scene.IsoGrid;
import as3isolib.graphics.Stroke;
import as3isolib.display.primitive.IsoBox;
import as3isolib.display.IsoSprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import eDpLib.events.ProxyEvent;
import as3isolib.geom.Pt;
import as3isolib.geom.IsoMath;
import as3isolib.graphics.SolidColorFill;
// before class
public class MyIsoGame extends MovieClip {
public var scene:IsoScene;
public var view:IsoView ;
public var CELLSIZE:int = 30;//------This is very important to remember cell size. This will affect placement of objects
var zoomFactor:Number = 1;////Zoom Factor heerrrreee--------------------
var s1:IsoSprite = new IsoSprite();
var wr:IsoSprite = new IsoSprite();
var wre:IsoSprite = new IsoSprite();
var g1:IsoSprite = new IsoSprite();
var b1:IsoSprite = new IsoSprite();
var b2:IsoSprite = new IsoSprite();
var b3:IsoSprite = new IsoSprite();
public function MyIsoGame() {
// constructor code
trace("hello from constructor");
scene = new IsoScene();
view = new IsoView();
view.setSize((stage.stageWidth), stage.stageHeight);
view.clipContent = true;
view.showBorder = false;
view.addScene(scene);
view.addEventListener(MouseEvent.MOUSE_DOWN, onStartPan, false, 0, true);
view.addEventListener(MouseEvent.MOUSE_WHEEL, onZoom, false, 0, true);
addChild(view);
var g:IsoGrid = new IsoGrid();
g.addEventListener(MouseEvent.CLICK, gridClick);
g.cellSize=30;
g.setGridSize(6,6);
g.y=0;
g.x=0;
g.gridlines = new Stroke(2,0x666666);
g.showOrigin = false;
scene.addChild(g);
g.addEventListener(MouseEvent.CLICK, grid_mouseHandler);
var box:IsoBox = new IsoBox();
box.setSize(10, 10, 10);
box.moveTo(50,50,0);
scene.addChild(box);
wr.setSize(30, 30, 30);
wr.moveTo(60, 0, 0);
wr.sprites=[new Wrecked()];
scene.addChild(wr);
wre.setSize(30, 30, 30);
wre.moveTo(30, 0, 0);
wre.sprites=[new Wrecked()];
scene.addChild(wre);
g1.setSize(30, 30, 30);
g1.moveTo(150, 150, 0);
g1.sprites=[new Gold()];
scene.addChild(g1);
b1.setSize(30, 30, 30);
b1.moveTo(120, 120, 0);
b1.sprites=[new Blue()];
scene.addChild(b1);
b2.setSize(30, 30, 30);
b2.moveTo(120, 150, 0);
b2.sprites=[new Blue()];
scene.addChild(b2);
b3.setSize(30, 30, 30);
b3.moveTo(150, 120, 0);
b3.sprites=[new Blue()];
scene.addChild(b3);
scene.render();
stage.addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheel);///MOUSE WHEEL CONTROL
stage.addEventListener (KeyboardEvent.KEY_DOWN, keyboarddownlistener)
}
private function gridClick(event:ProxyEvent):void
{
var me:MouseEvent = MouseEvent(event.targetEvent);
var p:Pt = new Pt(me.localX, me.localY);
IsoMath.screenToIso(p);
y
}
private var panPt:Pt;
private function onStartPan(e:MouseEvent):void
{
panPt = new Pt(stage.mouseX, stage.mouseY);
view.removeEventListener(MouseEvent.MOUSE_DOWN, onStartPan);
view.addEventListener(MouseEvent.MOUSE_MOVE, onPan, false, 0, true);
view.addEventListener(MouseEvent.MOUSE_UP, onStopPan, false, 0, true);
}
private function onPan(e:MouseEvent):void
{
view.panBy(panPt.x - stage.mouseX, panPt.y - stage.mouseY);
panPt.x = stage.mouseX;
panPt.y = stage.mouseY;
}
private function boxClick(e:Event)
{
view.centerOnIso(e.target as IsoBox);
}
private function onStopPan(e:MouseEvent):void
{
view.removeEventListener(MouseEvent.MOUSE_MOVE, onPan);
view.removeEventListener(MouseEvent.MOUSE_UP, onStopPan);
view.addEventListener(MouseEvent.MOUSE_DOWN, onStartPan, false, 0, true);
}
private var zoomValue:Number = 1;
private function onZoom(e:MouseEvent):void
{
if(e.delta > 0)
zoomValue += 0.10;
if(e.delta < 0)
zoomValue -= 0.10;
view.currentZoom = zoomValue;
}
///----------------Grid Mouse Handler
public function grid_mouseHandler (evt:ProxyEvent):void
{
var mEvt:MouseEvent = MouseEvent(evt.targetEvent);
var pt:Pt = new Pt(mEvt.localX, mEvt.localY);
IsoMath.screenToIso(pt);
var roundedX:int = int(pt.x)/30;
var roundedY:int= int(pt.y)/30;
trace("transformed point = "+roundedX +","+roundedY);
///Code that allows things to be put down, located here.
var s:IsoSprite= new IsoSprite();
s.sprites=[new Base()];
s.setSize(30, 30, 30);//Varies via Cell size-
s.moveTo(roundedX*30, roundedY*30, 0);
scene.addChild(s);
scene.render();
}///------------------Grid Mouse Handler
public function mouseWheel (event:MouseEvent){
trace("The Delta value isss: " + event.delta);
//Get current view zoom
zoomFactor+=event.delta*0.04;
view.zoom(zoomFactor)
}
public function keyboarddownlistener(e:KeyboardEvent){
{//Screen-Movement Code
if (e.keyCode == 40)
{// The numbers represent the keyboard buttons
trace("Down Arrow")// I've left these trace commands so you can get a better idea of which one is what.-William 22/04/14
view.pan(0,5);
scene.render();
//Down arrow???
}
}
if (e.keyCode == 38)
{
trace("Up Arrow")
view.pan(0,-5);
scene.render();
//Up arrow???
}
if (e.keyCode == 37)
{
trace("Left Arrow")
view.pan(5,0);
scene.render();
//Left arrow???
}
if (e.keyCode == 39)
{
trace("Right Arrow")
view.pan(-5,0);
scene.render();
//Right arrow???
}
/////OBJECT MOVEMENT code- For moving the donut around
///-- I am going to be working on a version of this game where--
///- everything can be controlled via a Keyboard only -William 22/04/14
if (e.keyCode == 65)
{
trace("A Left <--")
//view.x+=15;//Alternate version
s1.moveBy(30,0,0)
scene.render();
//Left?
}
if (e.keyCode == 68)
{
trace("D Right -->")
//view.x-=15;//Alternate version
s1.moveBy(-30,0,0)
scene.render();
//Right?
}
if (e.keyCode == 83)
{
trace("S Down --v")
//view.x-=15;//Alternate version
s1.moveBy(0,30,0)
scene.render();
//Down?
}
if (e.keyCode == 87)
{
trace("W Up --^")
//view.x-=15;//Alternate version
s1.moveBy(0,-30,0)
scene.render();
//Up?
}
}
}
}
I tried the code you supplied (without the numbers at the bottom) and it worked just fine for me.
error #1009 is a runtime error when you use a variable that hasn't been defined yet. I would suggest debugging from Flash Pro (ctrl + shift +enter) and let it show you where it breaks.
In your FLA, you said there is no code, but in the properties panel you do see the class field with "Splash" in it right? that is what links the class to the FLA.
It is possible that the runtime error you are seeing is not in the Splash class but in either BluBox or LoadingAnimation. Do those have class files? If not, take a look in the Library and you'll have two movie clips that are exported for actionScript with those names. Check in them to see if there might be some framescript.

If Stage (Init) throws error

This line throws a Stack Error (FlashDevelop) not compile error. I have other errors but I would thought the others might be flowing from this.
Can anyone get a sense of why its having trouble with this basic part of code?
Which is 1009 when displayed in external error viewer.
lines
if (stage) {init();}
throw this error.
It won't attach the second sprite without error- though it does seem to set on stage- traces don't give any results even they did before (with 4.4.2) however I just updated to 4.4.3.
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.*;
import flash.ui.Keyboard;
//import board;
import flash.accessibility.AccessibilityImplementation;
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.text.AntiAliasType;
import flash.utils.describeType;
import boxsprite;
import flash.net.*;
import flash.display.Stage;
import board;
/**
* ...
* #author Michael
*/
public class Main extends Sprite
{
internal var kanaList:Vector.<String> = new <String>["あ/ア", "あ/ア", "え/え", "え/え", "い/イ", "い/イ", "お/オ", "お/オ", "う/ウ", "う/ウ", "う/ウ", "う/ウ", "か/カ", "か/カ", "け/ケ", "け/ケ", "き/キ", "き/キ", "く/ク", "く/ク", "こ/コ", "こ/コ", "さ/サ", "さ/サ", " し/シ", " し/シ", "す/ス", "す/ス", "そ/ソ", "そ/ソ", "す/ス", "す/ス", "た/タ", "た/タ", "て/テ", "て/テ", " ち/チ", " ち/チ", "と/ト", "と/ト", "つ/ツ", "つ/ツ", "ら/ラ", "ら/ラ", "れ/レ", "れ/レ", "り/リ", "り/リ", "ろ/ロ", "ろ/ロ", "る/ル", "る/ル", "だ/ダ", "で/デ", "じ/ジ", "ど/ド", "ず/ズ", "ざ/ザ", "ぜ/ゼ", "ぞ/ゾ", "な/ナ", "ね/ネ", "に/二", "の/ノ", "ぬ/ヌ", "じゃ/ジャ", "じゅ/ジュ", "じょ/ジョ", "ん/ン", "しゃ/シャ", "しゅ/シュ", "しょ/ショ", "や/ヤ", "ゆ/ユ", "よ/ヨ", "は/ハ", "ひ/ヒ", "ふ/フ", "へ/ヘ", "ほ/ホ", "ば/バ", "ば/バ", "ぶ/ブ", "ぶ/ブ", "び/ビ", "び/ビ", "ぼ/ボ", "ぼ/ボ", "べ/ベ", "べ/ベ", "ぱ/パ", "ぴ/ピ", "ぷ/プ", "ぺ/ペ", "ぽ/ポ", "ま/マ", "み/ミ", " む/ム", "め/メ", "も/モ", "を/ヲ", "みゃ/ミャ", "みゅ/ミャ", "みょ/ミョ", "きゃ/キャ", "きゅ/キュ", "きょ/キョ", "にゃ/ニャ", "にゅ/ニュ", "にょ/ニョ", "びゃ/びゃ", "びゅ/ビュ", "びょ/ビョ", "  ひゃ/ヒャ", "ひゅ/ヒュ", "ひょ/ヒョ", "ぴゃ/ピャ", "ぴゅ/ピュ", "ぴょ/ピョ", "っ/ッ", "っ/ッ"];
internal var valueList:Vector.<uint>= new <uint>[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 10, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 20, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 1];
// Lists of Kana that can be replaced in the replace mode and the substitute Kana and Values
internal var selectghostList:Vector.<String>=new<String>["ま/マ","む/ム","も/モ","か/カ","く/ク","こ/コ","な/ナ","ぬ/ヌ","の/ノ","ば/バ","ぶ/ブ","ぼ/ボ","は/ハ","ふ/フ","ほ/ホ","ぱ/パ","ぷ/プ","ぽ/ポ"];
internal var selectkanaList:Vector.<String>=new <String>["みゃ/ミャ", "みゅ/ミャ", "みょ/ミョ", "きゃ/キャ", "きゅ/キュ", "きょ/キョ", "にゃ/ニャ", "にゅ/ニュ", "にょ/ニョ", "びゃ/びゃ", "びゅ/ビュ", "びょ/ビョ", "  ひゃ/ヒャ", "ひゅ/ヒュ", "ひょ/ヒョ", "ぴゃ/ピャ", "ぴゅ/ピュ", "ぴょ/ピョ"];
internal var selectghostvalueList:Vector.<uint>=new <uint>[2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2];
//Start list of playerHand contents as I don't know if Null is 0
internal var playernumber:uint;
internal var playerHand:Array = [[0], [0], [0], [0],[0], [0]];
[Embed(source = "C:/Windows/Fonts/Verdana.ttf", fontName = "Verdana", fontWeight = "bold", advancedAntiAliasing = "true", mimeType = "application/x-font")]
public static const VERD:Class;
/*[Embed(source="../lib/StartText.txt",mimeType="application/octet-stream")]
private var myFile:Class;
public var b:ByteArray = new myFile();
public var s:String = b.readUTFBytes(b.length)*/
public function Main():void
{
if (stage) {init();}
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//var board1:Sprite = new board();
//stage.addChild(board1);
//
var boardonScreen:Sprite = new board();
boardonScreen.x = 0;
boardonScreen.y = 0;
addChild(boardonScreen);
var box1:Sprite = new boxsprite();
box1.x = 480;
box1.y = 0;
addChild(box1);
}
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.*;
import flash.ui.Keyboard;
//import board;
import flash.accessibility.AccessibilityImplementation;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.text.AntiAliasType;
import flash.utils.describeType;
import flash.net.*;
import Set;
import StatusBox;
import Statusx;
import flash.display.InteractiveObject;
import flash.text.TextFieldType;
import flash.events.FocusEvent;
import fl.managers.FocusManager;
import flash.display.*;
import flash.display.Stage;
import flash.events.KeyboardEvent;
public class boxsprite extends Sprite
{
[Embed(source="../lib/Box.jpg")]
private var boxspriteClass:Class
internal var mode:uint= 1;
internal var displaytext:String;
internal var setBox:Boolean = false;
internal var onBoard:Array = [0];
internal var playerRound:uint = 1;
internal var round:uint = 1;
public var playernumber:uint;
public function boxsprite():void
{
trace (mode);
init2();
addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
choosetext();
}
private function init2():void
{
var boxsprite2:Bitmap = new boxspriteClass() as Bitmap;
this.addChild(boxsprite2); }
Doesn't matter how I write that part whether init or init()
Errors translated from Japanese with names removed.
null: TypeError: 1009 Error #.
at boxsprite / frontpage () ...Test \ New Project \ src \ boxsprite.as: 168]
at boxsprite / choosetext () ... Games \ Test \ New Project \ src \ boxsprite.as: 132]
at boxsprite () ... Test \ New Project \ src \ boxsprite.as: 53]
at Main / init () ...Test \ New Project \ src \ Main.as: 75]
at Main ().... \ Test \ New Project \ src \ Main.as: 56]
all functions are ():void except for eventlistener associated functions
Look for yourself no uninitialized variables- everything is defined before its used.
It totally fails to create textfields so that's why stage.focus fails.
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.*;
import flash.ui.Keyboard;
//import board;
import flash.accessibility.AccessibilityImplementation;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.text.AntiAliasType;
import flash.utils.describeType;
import flash.net.*;
import Set;
import StatusBox;
import Statusx;
import flash.display.InteractiveObject;
import flash.text.TextFieldType;
import flash.events.FocusEvent;
import fl.managers.FocusManager;
import flash.display.*;
import flash.display.Stage;
import flash.events.KeyboardEvent;
public class boxsprite extends Sprite
{
[Embed(source = "C:/Windows/Fonts/Verdana.ttf", fontName = "Verdana", fontWeight = "bold", advancedAntiAliasing = "true", mimeType = "application/x-font")]
public static const VERD:Class;
[Embed(source="../lib/Box.jpg")]
private var boxspriteClass:Class
internal var mode:uint;
internal var displaytext:String;
internal var setBox:Boolean = false;
internal var onBoard:Array = [0];
internal var playerRound:uint = 1;
internal var round:uint = 1;
internal var playernumber:uint;
internal var myTextBox:TextField = new TextField();
public function boxsprite():void
{mode = 1;
trace (mode);
init2();
this.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
}
private function init2():void
{
var boxsprite2:Bitmap = new boxspriteClass() as Bitmap;
this.addChild(boxsprite2);
choosetext();
}
protected function myKeyDown(e2:KeyboardEvent):void
{if (e2.keyCode ==Keyboard.ENTER)
{
/*mode 2 is beginning mode- setting a tile prompts a Set event which return a StatusBox event which unsets the tile
* mode 3 is return mode- setting a tile prompts a Set event which triggers a change to mode 4
* mode 4 return finish- add more tiles to return and either press Enter to end game and remove tile ID from hand list or double click any tile which trigger Status Box event to unset tiles
* mode 5 exchange simpler- setting a tile prompts a Set event which adds to temp list triggers function replace which a create simpleTile- double click on either triggers StatusBox event which kills the other tile and removes the tile from player list
* mode 6 exchange Kanji- setting a tile prompts Set event which triggers function newKanji which creates a kanjiTile-
* mode 7 set more tiles add to temp remove list double click on any set tile or click on Kanji tile to write Kanji or double click to complete press H to hide other tile to check with other players
* mode 8 end turn- press Enter to end score or press R to return tiles to hand
* mode 9 score
*/
switch (mode)
{ case 1:{mode = 2;
choosetext();
}
case 8:
{ mode = 9;}
case 9:
{mode = 2;
turn1();
}
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
if (setBox == false){
if (onBoard.length>1)
{mode = 8;
choosetext();}}
if (onBoard.length == 1)
{mode = 2;
choosetext();
turn1();
}
else if (setBox == true)
//set SetBox to true only for
{mode += 1;
choosetext();
}
}
}
if (e2.keyCode ==Keyboard.H)
{
navigateToURL(new URLRequest("http://wp.me/P3FUQl-n"));
}
//else if (e.Keycode == Keyboard.Q)
}
internal function choosetext():void
{switch (mode)
{case 1: {myTextBox.text = "";
frontpage();
trace ("mode is one"); }
case 2: {myTextBox.text = "Below are your tiles. Move them onto the board- double click to place. 下記のタイルは場所にボードをダブルクリックにそれらを移動している。"; }
case 3: {myTextBox.text = "Remove from your hand- place tile on the box (double click)- Press Enter when done.ボックス(ダブルクリック)であなたの手の場所のタイルから削除 - 終了したら、Enterキーを押します。";}
case 4: {myTextBox.text = "Press Enter to remove tiles and end your turn or double click any placed tile to not remove.タイルを削除してターンを終了するには、Enterキーを押したり、ダブル削除しないように、任意のタイル配置をクリックします。";}
case 5: {myTextBox.text =  "Place tile on box to get alternate kana tile- double click the one that you want あなたが望むものを得るために別の仮名タイルをダブルクリックを取得するためのボックスの上に置いてタイル" }
case 6: {myTextBox.text = "Place tile on box to get blank tile for writing kanji- click on it. 漢字を書くために空白のタイルを取得するためのボックスの上に置いてタイル. それをクリック";}
case 7: {myTextBox.text = "Place more tiles to form full reading. Press H to (un)hide other tiles so partner can check. Double click on the new or one old to select. 完全読書を形成するために多くのタイルを配置します。パートナーがチェックすることができるように他のタイルを隠すために、Hを押します。選択して新規または1歳をダブルクリックします。"; }
case 8: {myTextBox.text = "Press Enter if you or other players are OK with your word(s) or press R to return tiles. あなたや他のプレイヤーがあなたの言葉でOKであればEnterキーを押すか、タイルを返すためにRを押してください。"; }
case 9: {myTextBox.text = " Your score for this turn is below as calculated is below. Press S to reduce score and A to increase score. このターンのためにあなたのスコアは以下のように下にある計算されます。スコアAを押しますを高めるためにスコアSキーを押しを低減するために、"; }
}
}
protected function frontpage():void
{ //Introduction
trace ("draw");
var playerQ:TextField = new TextField();
playerQ.text = "Number of players 1-6?プレイヤーの数は(1)";
trace (playerQ.text);
playerQ.x = 0;
playerQ.y = 0;
playerQ.width = 64;
playerQ.height = 32;
playerQ.wordWrap = true;
this.addChild(playerQ);
var playernotext:TextField = new TextField();
playernotext.type = TextFieldType.INPUT;
playernotext.x = 0;
playernotext.y = 32;
playernotext.width = 32;
playernotext.height = 32;
playernotext.border = true;
addChild(playernotext);
stage.focus = playernotext;
playernotext.restrict = "1-6";
if (mode!=1){
if (playernotext.text != null)
{
playernumber = Number(playernotext.text); }
else
{playernumber = 1; }}
}
protected function turn1():void
{
if (playerRound > playernumber)
{playerRound = 1;
round += 1;
//create();
//display();
}
}
/*
deal();
}
internal function deal():void
{ var tileattrib:Array;
var kana:String;
var value:uint;
var newTileGroup:Array;
for (var i:uint = 1; i < 8; i += 1)
{
tileattrib = playerHand[playerRound[i]];
var newTile:Sprite = new tile(tileattrib[1],tileattrib[2]);
newTile.x = 15*32;
newTile.y = (15-i)*32;
newTileGroup.push(newTile);
addChild(newTile);}
}*/
protected function display():void
{
var format:TextFormat = new TextFormat("VERD", 20);
format.size = 20;
format.color = 0xFF0000;
format.font = "VERD";
myTextBox.defaultTextFormat = format;
myTextBox.setTextFormat(format);
myTextBox.antiAliasType = AntiAliasType.ADVANCED;
myTextBox.multiline = true;
myTextBox.textColor = 0xFF0000;
myTextBox.background = true;
myTextBox.border = true;
myTextBox.type = TextFieldType.DYNAMIC;
myTextBox.x=4;
myTextBox.y=4;
myTextBox.width = 32*4-4;
myTextBox.height = 32*6;
myTextBox.wordWrap = true;
stage.addChild(myTextBox);
myTextBox.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownScroll);
//
function mouseDownScroll(event:MouseEvent):void
{
myTextBox.scrollV+=1;
}
}
}
}
For some reason, if I reason it at least creates the instance and textfields though its still unresponsive to Enter key presses.
if I comment out the reference to Board() in Main()
package
{
import flash.display.Bitmap;
import flash.display.Sprite
import flash.text.TextField
import flash.text.TextFormat
import flash.events.MouseEvent
import flash.text.AntiAliasType
import flash.events.KeyboardEvent
import flash.ui.Keyboard
/**
* ...
* #author ...
*/
public class board extends Sprite
{
[Embed(source="../lib/Board.jpg")]
private var boardClass :Class;
public function board():void
{
start();
this.addEventListener(KeyboardEvent.KEY_DOWN, kill);
}
private var startBox:TextField = new TextField();
private function start():void
{var boardclass1:Bitmap = new boardClass() as Bitmap
this.addChild(boardclass1);
startBox.text = "Jabble. Click to Scroll Down. (下にスクロールする]をクリック) Instructions alternate between English and Japanese (translations). Press H for the help web page or put http://wp.me/P3FUQl-n in your web browser. Beneath is the Board and to the right is the Box. Press ENTER to go through the game stages- complete word, check and the score, deal next set of tiles. Press Spacebar to change the tile return modes- remove tiles from hand, exchange for alternate kana, exchange for a kanji. Click and Drag Tiles to move it and double click it set it on a square space on the Board or Box and click on the Box to change its mode. Jabble- 英語と日本語(訳)との間で交互に指示。を押して、ヘルプWebページのHまたはWebブラウザでhttp://wp.me/P3FUQl-nを置く。下には、取締役会であり、右に?などのさらなる命令ディスプレイボックスです.、ゲームを通してステージコンプリート単語、チェックとスコアを行くタイルの次のセットを扱うためにEnterキーを押します。モード·削除タイルの手札からタイル戻り、代替カナ引き換え、漢字と引き換えを変更するにはスペースバーを押します。クリックして、それを移動し、倍増するタイルをドラッグ 。クリックして、それを移動するにはタイルをドラッグし、ダブル会またはボックス上の正方形のスペースには、それを設定してクリックし、そのモードを変更するには、ボックスをクリックしてください " ;
var format:TextFormat = new TextFormat("VERD", 20);
format.size = 20;
format.color = 0xFF0000;
format.font = "VERD";
startBox.defaultTextFormat = format;
startBox.setTextFormat(format);
startBox.antiAliasType = AntiAliasType.ADVANCED;
startBox.multiline = true;
startBox.textColor = 0xFF0000;
startBox.background = true;
startBox.border = true;
startBox.x=32;
startBox.y=32;
startBox.width = 32*13;
startBox.height = 32*13;
startBox.wordWrap = true;
this.addChild(startBox);
startBox.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownScroll);
//
function mouseDownScroll(event:MouseEvent):void
{
startBox.scrollV+=1;
}
}
private function kill (e:KeyboardEvent):void
{ if (e.keyCode == Keyboard.ENTER)
{removeChild(startBox);
startBox = null;
this.removeEventListener(KeyboardEvent.KEY_DOWN, kill);
}
}
}
}

Correct usage of addtoStage when loading external swf

I am loading an external swf file into a parent swf file.
Previously, I was getting error 1009 and fixed that by using a listener event to add the swf to the stage before running any scripts.
The swf however fails to load completely when embedded into a parent swf as seen in this URL
http://viewer.zmags.com/publication/06b68a69?viewType=pubPreview#/06b68a69/1
Here is the code I am using.
Thank you for any input.
package
{
import com.greensock.TweenLite;
import flash.display.DisplayObject;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
public class slider5 extends Sprite
{
public var thumbPath:String = "Trailchair_thumb";
public var featPath:String = "Trailchair";
public var sliderIndex:Number = 1;
public var currBg:Bitmap = new Bitmap();
public var thumbCount:Number = 8;
public var thumbHolder:Sprite = new Sprite();
public var thumbMask:Sprite = new Sprite();
public var thumbX:Number = 0;
public var thmPadding:Number = 10;
public var thmWidth:Number;
public var navLeft:Sprite = new Sprite();
public var navRight:Sprite = new Sprite();
public var timer:Timer = new Timer(5000,0);
public var sliderDir:String = "fwd";
public function slider5()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
public function onAddedToStage(e:Event):void{
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
//THE BACKGROUND IMAGE
currBg.alpha = 1;
stage.addChildAt(currBg, 0);
changeBg(sliderIndex);
//The thumbMask a sprite with graphic rectangle
thumbMask.x = 87;
thumbMask.y = 572;
thumbMask.graphics.beginFill(0xFFFFFF);
thumbMask.graphics.drawRect(0,0, 406, 181);
stage.addChildAt(thumbMask, 2);
//The thumbSlider
thumbHolder.x = 228;
thumbHolder.y = 573;
stage.addChildAt(thumbHolder, 1);
thumbHolder.mask = thumbMask;
buildThumbs();
//add the nav
navLeft.x = 100;
navLeft.y = 609;
navRight.x = 496;
navRight.y = 609;
stage.addChildAt(navLeft, 4);
stage.addChildAt(navRight, 4);
var navBmp:Bitmap = new Bitmap();
navBmp.bitmapData = new navarrow(109,109);
var navBmp_Rt:Bitmap = new Bitmap();
navBmp_Rt.bitmapData = new navarrow(109,109);
navLeft.addChild(navBmp);
navLeft.scaleX *= -1;
navRight.addChild(navBmp_Rt);
navLeft.useHandCursor = true;
navLeft.buttonMode = true;
navRight.useHandCursor = true;
navRight.buttonMode = true;
navLeft.name = "left";
navRight.name = "right";
navLeft.addEventListener(MouseEvent.CLICK, navClick);
navRight.addEventListener(MouseEvent.CLICK, navClick);
//add the active item frame
var frame:Sprite = new Sprite();
frame.x = 226;
frame.y = 570;
frame.graphics.lineStyle(10, 0x000000);
frame.graphics.drawRect(0,0,131, 181);
stage.addChildAt(frame, 6);
timer.addEventListener(TimerEvent.TIMER, timeEvt);
timer.start();
}
public function changeBg(index):void
{
//set the first slide from our library and add to the stage
var currBg_Class:Class = getDefinitionByName( featPath + index ) as Class;
currBg.bitmapData = new currBg_Class(597,842);
//fade it in
TweenLite.from(currBg, 0.5, {alpha:0});
}
public function buildThumbs():void
{
var currThm:Class;
for (var i:uint = 1; i<=thumbCount; i++)
{
currThm = getDefinitionByName( thumbPath + i ) as Class;
var thmBmp:Bitmap = new Bitmap();
thmBmp.bitmapData = new currThm(126,176);
thmBmp.x = thumbX;
thumbHolder.addChild(thmBmp);
thumbX += thmBmp.width + thmPadding;
}
thmWidth = thmBmp.width + thmPadding;
}
public function navClick(e):void
{
timer.reset();
timer.start();
var dir:String = e.currentTarget.name;
if (dir=="left" && thumbHolder.x < 228 )
{
sliderIndex--;
TweenLite.to(thumbHolder, 0.5, {x:thumbHolder.x + thmWidth});
//thumbHolder.x = thumbHolder.x + thmWidth;
}
else if (dir=="right" && thumbHolder.x > - 724 )
{
sliderIndex++;
TweenLite.to(thumbHolder, 0.5, {x:thumbHolder.x - thmWidth});
//thumbHolder.x = thumbHolder.x - thmWidth;
}
if (sliderIndex == thumbCount)
{
sliderDir = "bk";
}
if (sliderIndex == 1)
{
sliderDir = "fwd";
}
changeBg(sliderIndex);
}
public function timeEvt(e):void
{
if (sliderDir == "fwd")
{
navRight.dispatchEvent(new Event(MouseEvent.CLICK));
}
else if (sliderDir == "bk")
{
navLeft.dispatchEvent(new Event(MouseEvent.CLICK));
}
}
}
}
If you still need it you can try these two suggestions. Note I didnt know about Zmags and initially assumed that it was your own domain name. That's why I suggested you use the Loader class. It worked for me when I did a test version of a parent.swf' that loaded a test 'child.swf' containing your code. It actually loaded the child swf without problems.
Change from extending Sprite to extending MovieClip
Avoid checking for added to stage in this project
Explanations:
Extending MovieClip instead of Sprite
I Long story short Flash wont like your swf extending Sprite then being opened by a parent loader that extends Movieclip. The ZMag player will be extending MovieClip. It's logical and the docs do confirm this in a way. Whether it fixes your issue or not just keep it MovieClip when using ZMags.
Avoiding Stage referencing in your code..
Looking at this Zmags Q&A documentaion:
http://community.zmags.com/articles/Knowledgebase/Common-questions-on-flash-integration
Looking at Question 4.. In their answer these two stand out.
Reference of the stage parameter in the uploaded SWF conflicting with the publication
Badly or locally referenced resources in the SWF you uploaded which cannot be found
Is it really necessary to have an added_to_stage check in this? If it wont hurt then I suggest dropping the stage_added checking from function slider5() and instead cut/paste in there the code you have from the function onAddedToStage(e:Event).
Hope it helps.

Getting from getCharBoundaries to BitMapData

I'm trying to convert all letters in a textfield to bitmap data. I then want to animate each of them. I'm able to return an array of rectangles using getCharBoundaries. But then how do I convert each letter to BitMapData?
package
{
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
public class LetterBitmapData extends Sprite
{
private var tf:TextField;
private var letterSprite:Sprite;
public function LetterBitmapData()
{
makeTF();
getRectangles();
};
private function makeTF():void
{
tf = new TextField();
tf.width = 400;
tf.height = 100;
tf.selectable = false;
tf.multiline = true;
tf.wordWrap = true;
tf.text = "Now is the winter of our discontent made glorious summer by this sun of York.";
tf.setTextFormat(new TextFormat("_sans", 16, 0));
addChild(tf);
}
private function getRectangles():Array
{
var result:Array = [];
var rectangle:Rectangle;
for (var i:int = 0; i < tf.text.length; i++)
{
rectangle = tf.getCharBoundaries(i);
result.push(rectangle); //create an array of CharBoundary rectangles
//trace("RECTANGLE x: " + rectangle.x + " y: " + rectangle.y + " width: " + rectangle.width + " height: " + rectangle.height );
}
return result;
}
}
}
You could animate your letters without turning them into Bitmaps as long as you're using embed fonts that is...
Instead of creating an array of rectangles, you could create an array of TextFields , associated to their specific rectangle in order to keep the coordinates of each letter. After that it should be possible to animate each TextField.