Copy link to clipboard
Copied
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.
var loader:Loader=new Loader();
var lc:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);
loader.load(new URLRequest('yourgameswf.swf'),lc);
addChild(loader);
Copy link to clipboard
Copied
you have to remember i can't see what you're talking about. so when you say, '..if i return to the drawing portion..' i do not know what's on-stage and what code is executing when you 'return to the drawing portion'.
Copy link to clipboard
Copied
‌
‌your right and I don't want to abuse on your great help and time in helping me understand this.
if it's okay with you, I'll make a detailed jpg of what is on screen and scripts or I can send you my .fla's
which ever you prefer.
I see you have a Flash deck and consultant business And your time is money. Please don't hesitate if this becomes more than just help. There is a fine line between help and a debugging contract. And I respect that. If you feel this is crossing that line just tell me your hourly rate and we'll work something out.
again thanks for your lightning fast responses and kind help in helping a newcomer in this flash world.
have a nice weekend
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
I managed to get one bug out of it. Navigation to each drawing, and back button disappearing.
Here is what I did :
I simply added a script to each "drawing" to go to certain frames. Ex. : Drawing 1 = frame 10, drawing 2 = Frame 20 and drawing 3 = frame 30.
On each frame, it loads your script
var loader1:Loader=new Loader();
var lc:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);
loader.load(new URLRequest('yourgameswf.swf'),lc);
addChild(loader);
I carefully named every Loader and lc instances to Loader1 lc1, Loader2 lc2 and Loader3, lc3.
With my deduction on how actionscript works, this seems to be correct.
I removed the script on frame 1:
var loader:Loader=new Loader();
var lc:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);
loader.load(new URLRequest('yourgameswf.swf'),lc);
addChild(loader);
so it no longer loads that script when entering frame 1. Which is perfect!
Now, when I click on any of the drawings, it loads the correct one as wanted because it goes to it's specific frame and loads the correct .swf.
So only one bug is left.
I can't acces go back to my main selection scene (Toutes sortes d'enfants),
Even If I start the app from the begining, All my other areas don't work.
This is what get :
[SWF] Henri%20Godon_A%20Colorier.swf - 1963785 bytes after decompression
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at HenriGodon_AColorier_fla::MainTimeline/backF()[HenriGodon_AColorier_fla.MainTimeline::frame1:5]
ArgumentError: Error #2108: Scene Toutes sortes d'enfants was not found.
at flash.display::MovieClip/gotoAndPlay()
at HenriGodon_AColorier_fla::MainTimeline/fl_ClickToGoToScene_62()[HenriGodon_AColorier_fla.MainTimeline::frame1:25]
[UnloadSWF] Henri%20Godon_A%20Colorier.swf
Test Movie terminated.
Is it unloading something it shouldn't ?
Copy link to clipboard
Copied
I also Added this on frame 1 of my drawing selection screen :
stop()
back_btn.addEventListener(MouseEvent.MOUSE_DOWN,backF);
function backF(e:MouseEvent):void{
loader1.unloadAndStop();
removeChild(loader1);
loader2.unloadAndStop();
removeChild(loader2);
loader3.unloadAndStop();
removeChild(loader3);
}
Copy link to clipboard
Copied
you have more than one object named back_btn and it's not clear what code relates to which button.
on the frame that displays 'a colorier' you should have something like:
var urlS:String;
var loader:Loader=new Loader();
var lc:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);
dh_btn.addEventListener(MouseEvent.CLICK,loadF);
dc_btn.addEventListener(MouseEvent.CLICK,loadF);
dp_btn.addEventListener(MouseEvent.CLICK,loadF);
function loadF(e:MouseEvent):void{
switch(e.currentTarget.name){
case 'dh_btn':
urlS='Dessin-Henri.swf';
break;
case 'dc_btn':
urlS=''Dessin-Cowboy.swf';
break;
case 'dp_btn':
urlS='Dessin-Poster.swf';
break;
}
loader.load(new URLRequest(urlS),lc);
addChild(loader);
}
/////////////////////////////////////////////////
in each of the 3 swfs that contain a back_btn, you should have on that swf's main timeline
back_btn.addEventListner(MouseEvent.CLICK,backF);
function backF(e:MouseEvent):void{
Loader(this.part).unloadAndStop();
}
Copy link to clipboard
Copied
I don't know what I'm doing wrong, it's getting worse.
Even if i paste that code in my Dessin-Henri.swf, I get compiling errors as nothing is defined.
I'm just having issues with the back button, and it can't find scenes anymore for some odd reason.
I'll keep on working with it. See what I did below. It might explain where I'm at now.
Thanks.
Copy link to clipboard
Copied
do you have a back_btn each loaded swf?
Copy link to clipboard
Copied
No an I got errors flying everywhere now.....
I'll erase everything and start from scratch, and folowing the steps carefully.
I'll keep you posted on how I'm doing.
Again, your patience is more that appreciated.
Copy link to clipboard
Copied
Okay,
I found that I've been getting errors when using "Test scene".
When using "Test Movie" All is fine!
Now, one part I did not succeed is creating a Back button in the drawing SWF ex. : Dessin-Henri.swf
My button is on stage with a unique name dh_btn
I just need a code that will compile okay and that button will go back to my "previous scene" called A Colorier.
Can that be done?
I think that after this. Everything should be fine.
Copy link to clipboard
Copied
dh_btn is on which stage, the dh.swf stage or the main stage that has the loader?
Copy link to clipboard
Copied
‌it's on the Dessin_Henri.swf stage.
hope that's ok. As trying to understand your proposed code, you seem to load it from the main stage to the dh.swf stage so that the reference to the main stage is still there When clicking on the dh_btn button.
I Think I might have trouble getting used to flash as it works similar to director in essence but is much more complex.
Copy link to clipboard
Copied
on the dessing_henri.swf main timeline where your dh_btn (back button) is located, use:
dh_btn.addEventListner(MouseEvent.CLICK,backF);
function backF(e:MouseEvent):void{
Loader(this.part).unloadAndStop();
}
Copy link to clipboard
Copied
OOkay I'll try that first thing tomorrow am.
i Think I tried that but when trying to compile my .swf it kept having trouble with loader.
I'll give you more details on this tomorrow morning.
Thanks again kglad! Your the best!
Copy link to clipboard
Copied
oops, there's a typo. that should be:
dh_btn.addEventListner(MouseEvent.CLICK,backF);
function backF(e:MouseEvent):void{
Loader(this.parent).unloadAndStop();
}
Copy link to clipboard
Copied
That's where I don't understand,
I'm in Dessin-Henri.swf, well the .FLA that will become the SWF. I imported my button, named it dh_btn in the properties panel.
clicked on frame 1 with nothing selected, pasted you code. Here is what I get :
| Scene 1, Layer 'Back Button', Frame 1, Line 5, Column 1 | 1180: Call to a possibly undefined method Loader. |
| Scene 1, Layer 'Back Button', Frame 1, Line 1, Column 1 | 1120: Access of undefined property dh_btn. |
It doesn't know what Loader is?
How can it not understand what my dh_btn is?
Copy link to clipboard
Copied
are you publishing for as3?
and you can't test that without loading it, just publish it.
Copy link to clipboard
Copied
Okay, I just noticed that in the publish settings it was set at Strict mode by default. So that didn't help me publish it.
Now I published successfully all 3 .SWF's for the drawings.
I then went back to my main .FLA and tested that one out. When I click on the drawings to load each SWF, this is what I get :
Dessing-Henri.swf :
ReferenceError: Error #1065: Variable dh_btn is not defined.
at Main/frame1()
Dessin-Cowboy.SWF :
ReferenceError: Error #1065: Variable dc_btn is not defined.
at Main/frame1()
Dessin-Poster.SWF :
ReferenceError: Error #1065: Variable dp_btn is not defined.
at Main/frame1()
Copy link to clipboard
Copied
you have a reference to those buttons in your main (loading) fla and those buttons don't exist there. they are in the loaded swfs.
Copy link to clipboard
Copied
I checked and double checked and no other references are in my main FLA for dh_btn,, dc_btn and dp_btn.
Could it be that I have to tell it what dh_btn is?
It only happens when I click on one of the drawings, so I guess the error comes form the SWF's.
I might be totally wrong!
Copy link to clipboard
Copied
click file>publish settings>swf and tick 'permit debugging'. retest.
the line and frame with the problematic code will be in the error message.
Copy link to clipboard
Copied
Could this be what your looking for?
ReferenceError: Error #1065: Variable dh_btn is not defined.
at Main/frame1()
Cannot display source code at this location.
Copy link to clipboard
Copied
not really.
are you publishing those swfs that load without error?
can you publish your main (loading) swf without error?
Copy link to clipboard
Copied
I can publish the Main .FLA without error but, I can't publish the Dessin-Henri, Dessin-Cowboy, and Dessin-Poster without error.
This is what I get when publish it in strict mode and warning mod on :
| Scene 1, Layer 'Actions', Frame 1, Line 5, Column 1 | 1180: Call to a possibly undefined method Loader. |
| Scene 1, Layer 'Actions', Frame 1, Line 1, Column 1 | 1120: Access of undefined property dh_btn. |
This is the script I have in the Actions layer frame 1
dh_btn.addEventListner(MouseEvent.CLICK, backF);
function backF(e: MouseEvent): void {
Loader(this.parent).unloadAndStop();
}
I even triple checked in all of the 3 Dessin-xxx.swf to make sure there wasn't a duplicate of the btn.
I know we're on the verge of getting it!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now