Skip to main content
Participating Frequently
June 18, 2015
Answered

Need help integration a AS3 drawing game into a .fla

  • June 18, 2015
  • 1 reply
  • 4159 views

Hi,

I created a drawing game by following a tutorial on this website : http://code.tutsplus.com/tutorials/create-a-basic-drawing-application-in-flash--active-1627

It was pretty straight forward. (you can download the source file to have the same code as me and save time).

Now to the fun part!

I previously created an iPad app in Flash. Works great by the way and is published on the App Store. (Search for : Henri Godon -> free app)

My client wants this drawing game to be incorporated in his app with a possibility of 3 different images to color opon. Which is pretty easy to do.

I thought that just doing a simple copy/paste and including the scripts would do the trick.... WRONG! I keep getting errors once I try to export it or test it out.

My App works great without the game. And the game works great alone. It's only one I try to embed it that I'm stuck.

Here are my errors, hope someone has an easy DIY way that I'm not aware of since I have never done this before.

ERROR 1:

1037 : Packages cannot be nested.

here is what it is referring to in the Main.as script :

package

{

  import PNGEncoder;

  import flash.display.MovieClip;

  import flash.display.Shape;

  import flash.display.DisplayObject;

  import flash.text.TextField;

  import flash.text.TextFormat;

  import flash.text.TextFieldType;

  import flash.text.TextFieldAutoSize;

  import flash.display.BitmapData;

  import flash.geom.ColorTransform;

  import flash.events.MouseEvent;

  import flash.events.Event;

  import flash.utils.ByteArray;

  import flash.net.FileReference;

  public class Main extends MovieClip

  {

ERROR 2:

Even if I try to remove that part, then I get an other error saying

1114: The public attribute can only be used inside a package. (which is kinda obvious)

1084: Syntax error: expecting leftbrace before var.

So nothing works after that...

I added the Main.as in the ActionScript setting in the Document class. So I know it is loaded in a way, but after that I'm stuck!

Please help out! I'll do anything.

This topic has been closed for replies.
Correct answer kglad

‌hi kglad,

yes yes I can create a swf with it. How would I import it so it could play on iPad?

not sure what a loader class is or how to add the class to my project.

feeling like a noob here. I just transferred from using Director lingo to learning flash in a week.

DIrector can't make 64bit iOS apps... Learning curve is kinda steep.


var loader:Loader=new Loader();

var lc:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);

loader.load(new URLRequest('yourgameswf.swf'),lc);

addChild(loader);

1 reply

kglad
Community Expert
June 18, 2015

you have mismatched curly brackets in your class.

Participating Frequently
June 18, 2015

not too sure where... Here is the complet Main.as code :

package

{

  import PNGEncoder;

  import flash.display.MovieClip;

  import flash.display.Shape;

  import flash.display.DisplayObject;

  import flash.text.TextField;

  import flash.text.TextFormat;

  import flash.text.TextFieldType;

  import flash.text.TextFieldAutoSize;

  import flash.display.BitmapData;

  import flash.geom.ColorTransform;

  import flash.events.MouseEvent;

  import flash.events.Event;

  import flash.utils.ByteArray;

  import flash.net.FileReference;

  public class Main extends MovieClip

  {

  /* Variables */

  /* Pencil Tool shape, everything drawed with this tool and eraser is stored inside board.pencilDraw */

  var pencilDraw:Shape = new Shape();

  /* Text format */

  var textformat:TextFormat = new TextFormat();

  /* Colors */

  var colorsBmd:BitmapData;

  var pixelValue:uint;

  var activeColor:uint = 0x000000;

  /* Active var, to check wich tool is active */

  var active:String;

  /* Shape size color */

  var ct:ColorTransform = new ColorTransform();

  public function Main():void

  {

  textformat.font = "Quicksand Bold Regular";

  textformat.bold = true;

  textformat.size = 16;

  convertToBMD();

  addListeners();

  /* Hide tools highlights */

  pencil.visible = false;

  hideTools(eraser, txt);

  }

  /* Pencil Tool */

  private function PencilTool(e:MouseEvent):void

  {

  /* Quit active tool */

  quitActiveTool();

  /* Set to Active */

  active = "Pencil";

  /* Listeners */

  board.addEventListener(MouseEvent.MOUSE_DOWN, startPencilTool);

  board.addEventListener(MouseEvent.MOUSE_UP, stopPencilTool);

  /* Highlight */

  highlightTool(pencil);

  hideTools(eraser, txt);

  ct.color = activeColor;

  shapeSize.transform.colorTransform = ct;

  }

  private function startPencilTool(e:MouseEvent):void

  {

  pencilDraw = new Shape();

  board.addChild(pencilDraw);

  pencilDraw.graphics.moveTo(mouseX, mouseY);

  pencilDraw.graphics.lineStyle(shapeSize.width, activeColor);

  board.addEventListener(MouseEvent.MOUSE_MOVE, drawPencilTool);

  }

  private function drawPencilTool(e:MouseEvent):void

  {

  pencilDraw.graphics.lineTo(mouseX, mouseY);

  }

  private function stopPencilTool(e:MouseEvent):void

  {

  board.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilTool);

  }

  /* Eraser Tool */

  private function EraserTool(e:MouseEvent):void

  {

  /* Quit active tool */

  quitActiveTool();

  /* Set to Active */

  active = "Eraser";

  /* Listeners */

  board.addEventListener(MouseEvent.MOUSE_DOWN, startEraserTool);

  board.addEventListener(MouseEvent.MOUSE_UP, stopEraserTool);

  /* Highlight */

  highlightTool(eraser);

  hideTools(pencil, txt);

  ct.color = 0x000000;

  shapeSize.transform.colorTransform = ct;

  }

  private function startEraserTool(e:MouseEvent):void

  {

  pencilDraw = new Shape();

  board.addChild(pencilDraw);

  pencilDraw.graphics.moveTo(mouseX, mouseY);

  pencilDraw.graphics.lineStyle(shapeSize.width, 0xFFFFFF);

  board.addEventListener(MouseEvent.MOUSE_MOVE, drawEraserTool);

  }

  private function drawEraserTool(e:MouseEvent):void

  {

  pencilDraw.graphics.lineTo(mouseX, mouseY);

  }

  function stopEraserTool(e:MouseEvent):void

  {

  board.removeEventListener(MouseEvent.MOUSE_MOVE, drawEraserTool);

  }

  /* Text Tool */

  private function TextTool(e:MouseEvent):void

  {

  /* Quit active tool */

  quitActiveTool();

  /* Set to Active */

  active = "Text";

  /* Listener */

  board.addEventListener(MouseEvent.MOUSE_UP, writeText);

  /* Highlight */

  highlightTool(txt);

  hideTools(pencil, eraser);

  }

  private function writeText(e:MouseEvent):void

  {

  var textfield = new TextField();

  textfield.type = TextFieldType.INPUT;

  textfield.autoSize = TextFieldAutoSize.LEFT;

  textfield.selectable = false;

  textfield.defaultTextFormat = textformat;

  textfield.textColor = activeColor;

  textfield.x = mouseX;

  textfield.y = mouseY;

  stage.focus = textfield;

  board.addChild(textfield);

  }

  /* Clear Tool */

  private function clearBoard(e:MouseEvent):void

  {

  /* Create a blank rectangle on top of everything but board */

  var blank:Shape = new Shape();

  blank.graphics.beginFill(0xFFFFFF);

  blank.graphics.drawRect(0, 0, board.width, board.height);

  blank.graphics.endFill();

  board.addChild(blank);

  }

  /* Default colors function */

  private function convertToBMD():void

  {

  colorsBmd = new BitmapData(colors.width,colors.height);

  colorsBmd.draw(colors);

  }

  private function chooseColor(e:MouseEvent):void

  {

  pixelValue = colorsBmd.getPixel(colors.mouseX,colors.mouseY);

  activeColor = pixelValue;//uint can be RGB!

  ct.color = activeColor;

  shapeSize.transform.colorTransform = ct;

  }

  /* Quit active function */

  private function quitActiveTool():void

  {

  switch (active)

  {

  case "Pencil" :

  board.removeEventListener(MouseEvent.MOUSE_DOWN, startPencilTool);

  board.removeEventListener(MouseEvent.MOUSE_UP, stopPencilTool);

  case "Eraser" :

  board.removeEventListener(MouseEvent.MOUSE_DOWN, startEraserTool);

  board.removeEventListener(MouseEvent.MOUSE_UP, stopEraserTool);

  case "Text" :

  board.removeEventListener(MouseEvent.MOUSE_UP, writeText);

  default :

  }

  }

  /* Highlight active Tool */

  private function highlightTool(tool:DisplayObject):void

  {

  tool.visible=true;

  }

  private function hideTools(tool1:DisplayObject, tool2:DisplayObject):void

  {

  tool1.visible=false;

  tool2.visible=false;

  }

  /* Change shape size */

  private function changeShapeSize(e:MouseEvent):void

  {

  if (shapeSize.width >= 50)

  {

  shapeSize.width = 1;

  shapeSize.height = 1;

  /* TextFormat */

  textformat.size = 16;

  }

  else

  {

  shapeSize.width += 5;

  shapeSize.height=shapeSize.width;

  /* TextFormat */

  textformat.size+=5;

  }

  }

  private function addListeners():void

  {

  pencilTool.addEventListener(MouseEvent.MOUSE_UP, PencilTool);

  eraserTool.addEventListener(MouseEvent.MOUSE_UP, EraserTool);

  textTool.addEventListener(MouseEvent.MOUSE_UP, TextTool);

  clearTool.addEventListener(MouseEvent.MOUSE_UP, clearBoard);

  colors.addEventListener(MouseEvent.MOUSE_UP, chooseColor);

  sizePanel.addEventListener(MouseEvent.MOUSE_UP, changeShapeSize);

  shapeSize.addEventListener(MouseEvent.MOUSE_UP, changeShapeSize);

  }

  }

}

Participating Frequently
June 22, 2015

anything i can help you with via the adobe forums is free.  but downloading and investigating files i don't do for free.

that said, i believe this can be solved without requiring any files to be downloaded/investigated.

copying and pasting code and explaining where the code is located should be sufficient.  you don't have so much code that this is burdensome.


Hi kglad,

I hope you had a nice weekend!

I would like to start off by saying thankyou for the time you are putting in helping me understand Flash and working out my bugs.

I prepared a detailed JPG of what is what and scripts associated to every button.

Bugs That I have :

When I click on a drawing, the SWF loads fine and back button appears, If I click it, it goes back to the scene (A colorier) as supposed to. But once that scene is loaded the Back button disappears.

In the first scene (Toutes sortes d'enfants) Shown Below, All of my buttons which lead to different scenes don't load anymore. This is the type of error I get, though it was working before, so there is a conflict... :

ArgumentError: Error #2108: Scene A Colorier was not found.

at flash.display::MovieClip/gotoAndPlay()

at HenriGodon_Toutessortesd_enfants_fla::MainTimeline/fl_ClickToGoToScene_63()[HenriGodon_Toutessortesd_enfants_fla.MainTimeline::frame25:112]

I know one thing I am not doing right is naming all my assets and buttons etc... Which can be in part confusing. This is my error I learned while learning Flash and all the differences with Adobe Director.

In making an app like this, should I do it all in one .FLA using multiple scenes? Or mak a main .FLA and load SWF's for all the differnent sections of the App ?

I hope I'm clear, if not don't hesitate in asking questions.

Thanks again!