Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need help integration a AS3 drawing game into a .fla

Explorer ,
Jun 18, 2015 Jun 18, 2015

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.

TOPICS
ActionScript
4.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 18, 2015 Jun 18, 2015

var loader:Loader=new Loader();

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

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

addChild(loader);

Translate
Community Expert ,
Jun 24, 2015 Jun 24, 2015

open dessin-henri.fla and save it as dessin-henri_bu.fla

then create a new fla, add a movieclip to frame 1 with instance name dh_btn and add the same script showing in message 49.  test.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 24, 2015 Jun 24, 2015

same error :

Scene 1, Layer 'Layer 1', Frame 1, Line 1, Column 11120: Access of undefined property dh_btn.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2015 Jun 24, 2015

click the movieclip in frame 1 that you think is dh_btn and check the properties panel.  do you see its instance name there?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 24, 2015 Jun 24, 2015

Man I can't believe that was hidden there. I thought just giving it a name was sufficient.

Now back to Dessin-Henri.fla, I changed the instance name of the button to dh_btn. Now that error is gone.

Now I have :

TypeError: Error #1006: addEventListner is not a function.

  at Main/frame1()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2015 Jun 24, 2015

are you publishing for as3?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 24, 2015 Jun 24, 2015

yes here are my settings.

I'm publishing for IOS in my .FLA where most of my app is.

Screen Shot 2015-06-24 at 10.51.44 PM.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2015 Jun 25, 2015

tick 'permit debugging' in your main swf and retest to more detailed info about the error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 25, 2015 Jun 25, 2015

Here is what I got :

By choosing Debug only

[SWF] Dessin-Henri.swf - 157100 bytes after decompression

TypeError: Error #1006: addEventListner is not a function.

  at Main/frame1()

Cannot display source code at this location.

Tried it by clicking debug movie in Air Launcher Desktop and got this :

[SWF] Henri%20Godon.swf - 60704565 bytes after decompression

[SWF] Dessin-Henri.swf - 157100 bytes after decompression

TypeError: Error #1006: addEventListner is not a function.

  at Main/frame1()

Cannot display source code at this location.

Is there another way to see what is happening?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2015 Jun 25, 2015

there's a typo:

that should be addEventListener, not addEventListner

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 25, 2015 Jun 25, 2015

Okay, that one is okay now.

When I test it, it loads the Dessin-Henri.swf without a hitch but when I click on the back button I get :

ReferenceError: Error #1065: Variable Loader is not defined.

  at Main/backF()

Does that mean we must define the var Loader in the Main.as that came with the Drawing App?

Or is it in the dh_btn script itself?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2015 Jun 25, 2015

tick 'permit debugging' in all the fla's and then publish.

then test.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 25, 2015 Jun 25, 2015

cool.

here is the message :

[SWF] Dessin-Henri.swf - 158362 bytes after decompression

ReferenceError: Error #1065: Variable Loader is not defined.

  at Main/backF()[Main::frame1:3]

[UnloadSWF] Henri%20Godon.swf

Test Movie terminated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2015 Jun 25, 2015

are you testing by running the main fla, NOT dessing-henri.fla?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 25, 2015 Jun 25, 2015

Yeah I'm testin in the main.fla, cause I guess it won't be able to know where to go back to.

Here is the full error :

[SWF] Henri%20Godon.swf - 60704565 bytes after decompression

[SWF] Dessin-Henri.swf - 158362 bytes after decompression

ReferenceError: Error #1065: Variable Loader is not defined.

  at Main/backF()[Main::frame1:3]

[UnloadSWF] Henri%20Godon.swf

Test Movie terminated.

Henri%20Godon.swf is my main file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2015 Jun 25, 2015

i don't understand why you're seeing this, [SWF] Dessin-Henri.swf - 158362 bytes after decompression

with henry godon.fla open in flash pro, you click control>test movie>in flash professional.

is that exactly what you're doing?

if yes, then you see the error message?  so you do something and see the error message?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 25, 2015 Jun 25, 2015

I test the Henri Godom.fla in Flash Pro control>test

I then navigate through my menu up to the 3 drawings scene.

I then click on the first drawing > Dessin-Henri.swf

I can draw fine as supposed to.

If I click on the back button, that's where I get my error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2015 Jun 25, 2015

i can't duplicate that (unless you have some other code in the main fla, or elsewhere) that's unlloading d-h.swf before the code i suggested executes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 25, 2015 Jun 25, 2015

Here is what I got at frame 10 in the Main.fla

stop();

var loader1:Loader=new Loader();

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

loader1.load(new URLRequest('Dessin-Henri.swf'),lc1);

addChild(loader1);

The reason why it's at frame 10 is mainly because I have a script at frame 1, when you click on the first drawing, it leads you to frame 10, where is loads the proper SWF.

Is that script Okay?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2015 Jun 26, 2015

in d-h.fla, comment out the Loader(this.parent).unloadAndStop() line of code and above it place

trace(this.parent);

publish a new d-h.swf

in your main fla, test the d-h coloring and report the trace output.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 26, 2015 Jun 26, 2015

Hi kglad,

Here is my script in d-h.fla :

dh_btn.addEventListener(MouseEvent.CLICK, backF);

function backF(e: MouseEvent): void {

  trace(this.parent);

/** Loader(this.parent).unloadAndStop(); **/

}

Here is the report in the Main.fla once tested :

[SWF] Henri%20Godon.swf - 60704565 bytes after decompression

[SWF] Dessin-Henri.swf - 158339 bytes after decompression

[object Loader]

[UnloadSWF] Henri%20Godon.swf

Test Movie terminated.

It reported [object Loader] only when I clicked on the Back button.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2015 Jun 26, 2015

now replace that code with the following and paste the output:

dh_btn.addEventListener(MouseEvent.CLICK, backF);

function backF(e: MouseEvent): void {

  trace(this.parent);

  Loader(this.parent).unloadAndStop();

trace('after');

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 26, 2015 Jun 26, 2015

Here is what I got after I raplaced it in Dessin-Henri.fla

[SWF] Henri%20Godon.swf - 60704565 bytes after decompression

[SWF] Dessin-Henri.swf - 158401 bytes after decompression

[object Loader]

ReferenceError: Error #1065: Variable Loader is not defined.

  at Main/backF()[Main::frame1:7]

[UnloadSWF] Henri%20Godon.swf

Test Movie terminated

Again only after I clicked.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 27, 2015 Jun 27, 2015

try:

dh_btn.addEventListener(MouseEvent.CLICK, backF);

function backF(e: MouseEvent): void {

var ldr:Loader = this.parent;

ldr.unloadAndStop();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 28, 2015 Jun 28, 2015

hmm, I got this when trying to publish the Dessin-Henri.swf :

Scene 1, Layer 'Actions', Frame 1, Line 3, Column 101046: Type was not found or was not a compile-time constant: Loader.

I still tried to test the Main.fla but couldn't draw anymore.

I'm kinda stumped and don't have a clue of what is what.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2015 Jun 28, 2015

try:

import flash.display.Loader

dh_btn.addEventListener(MouseEvent.CLICK, backF);

function backF(e: MouseEvent): void {

var ldr:Loader = this.parent;

ldr.unloadAndStop();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines