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

Code error

Participant ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

Using Animate CC, I have developed hundreds of Flash animations to help teachers instruct full classes of music students.

With the decline of Flash Player, I am moving to an AIR application that can load/unload swfs with a button click.

With this code, I get the following errors (Line 14 is the “removeChild” line.):

Scene 1, Layer 'Action', Frame 1, Line 14, Column 13 1084: Syntax error: expecting colon before leftparen.

Scene 1, Layer 'Action', Frame 1, Line 15, Column 2        1084: Syntax error: expecting identifier before var.

Scene 1, Layer 'Action', Frame 1, Line 15, Column 19 1084: Syntax error: expecting rightbrace before colon.

  1. StageScaleMode.EXACT_FIT
  2. import flash.display.Loader;
  3. import flash.net.URLRequest;
  4. var Xpos:Number = 0
  5. var Ypos:Number = 40
  6. var swf:MovieClip;
  7. var loader:Loader = new Loader();
  8. //Btns universal function
  9. function btnClick(event:MouseEvent);void{
  10. removeChild(loader);
  11. var newSWFRequest:URLRequest = new URLRequest("RhythmBee/" + event.target.name + ".swf");
  12. loader.load(newSWFRequest);
  13. loader.x = Xpos;
  14. loader.y = Ypos;
  15. addChild(loader);
  16. }
  17. /// btn listeners
  18. Unit1.addEventListener(MouseEvent.Click.btnClick);

Any help will be appreciated.

TOPICS
Development

Views

761

Translate

Translate

Report

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

LEGEND , Jan 24, 2018 Jan 24, 2018

I don't think that removeChild of a Loader will unload the SWF. Doing loader.unload() should do that. Not sure if it would complain if you had never done loader.load().

In general, if you want to remove something that may not have a parent at the time, you can do something like this:

if(loader.parent) loader.parent.removeChild(loader);

Or a sloppier but easier to think of way would be:

addChild(loader);

removeChild(loader);

Nobody would see it pop on top, because it's immediately gone after that.

The r

...

Votes

Translate

Translate
LEGEND ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

At the time you remove loader, you haven't yet added it, and so it has no parent, to remove from. As you're about to add it anyway, just remove that line.

Something to know about, if you load SWFs into a mobile AIR app the SWF normally can't contain any code. If you're just building an app to load onto your own mobile device, there is an interpreter mode you can use, and then SWFs with code are allowed.

If you're doing desktop (and this may apply to mobile), SWFs with code may be allowed, I'm not sure! In any case, there are security concerns you need to know about. Read through this topic to get an idea of what's involved:

Loading external swf into Air App

By the way, if your animations have no code in them you might be able to convert them to HTML5 Canvas, and then play them as part of a web page, that would also be able to work on mobile. If there is a little bit of code, you could manually convert the ActionScript to JavaScript, it need not be very hard.

Votes

Translate

Translate

Report

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
Participant ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

Thanks Colin!

Regarding “remove loader” - I have programmed that as a universal button click that will need to unload any SWF that has been previously loaded as it also loads the new SWF.

Regarding code in SWFs. I am aware of that problem, but I can’t imagine why that issue exists. Why!!!

My swfs are code-rich – but at this point I am only working toward desktop functionality. So I hope things will work ok.

Thanks again

Votes

Translate

Translate

Report

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
LEGEND ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

I don't think that removeChild of a Loader will unload the SWF. Doing loader.unload() should do that. Not sure if it would complain if you had never done loader.load().

In general, if you want to remove something that may not have a parent at the time, you can do something like this:

if(loader.parent) loader.parent.removeChild(loader);

Or a sloppier but easier to think of way would be:

addChild(loader);

removeChild(loader);

Nobody would see it pop on top, because it's immediately gone after that.

The reason that code in an external SWF that you load into a mobile AIR app at runtime, isn't allowed, is because of app store rules, most notably Apple's rules. If you could load any online SWF with code you could set up your own competing App Store. People would get your shell app for free, then would pay you directly for modules, cutting out Apple, Google, Amazon, and so on.

Now, ironically it's fairly easy to achieve that by using HTML and web views, and essentially Safari is doing that, every web page is a new experience, without any store approval. But we still have to live with the external code rules.

There is a way to publish server based SWFs that do need code. It's not trivial, but is possible. Should you ever need to do that.

Votes

Translate

Translate

Report

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
Participant ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

Colin,

I was ready to throw a party!! Everything worked SO WELL!!

Then I tried the AIR installation version of my app that I want to load the swfs. There is no response from the buttons in that app, although the swf does exactly what I want it to do.

Any advice?

Thanks for your help!

BuzzyToo

Votes

Translate

Translate

Report

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
LEGEND ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

If you go into Publish Settings you can select Permit debugging. Then if you do a Debug/Debug Movie/In AIR Debug Launcher (Desktop), you should be taken to the line of code that has a problem, and look at the variables to see what is not right.

Votes

Translate

Translate

Report

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
Participant ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

Thanks, Colin!

Everything worked fine - just as it did in the swf format. Here is the output for that Debug session. And there were no lines of code that came up unless this output tells you something that I am not getting.

Attempting to launch and connect to Player using URL C:/Users/Buzzy/Desktop/RhythmBee/Table of Contents - Streaming - Rhythm and WS - 2018-app.xml

[SWF] Table%20of%20Contents%20-%20Streaming%20-%20Rhythm%20and%20WS%20-%202018.swf - 124228 bytes after decompression

[SWF] Unit1.swf - 782037 bytes after decompression

[UnloadSWF] Unit1.swf

[SWF] Unit1.swf - 782037 bytes after decompression

[UnloadSWF] Unit1.swf

[SWF] Unit1.swf - 782037 bytes after decompression

[UnloadSWF] Unit1.swf

Thanks again,

Buzzy

Votes

Translate

Translate

Report

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
LEGEND ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

The debug test has a different set of security rules. Read that topic I told you about in message #1. You may need to do some loaderContext things that you don't currently have.

Votes

Translate

Translate

Report

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
Participant ,
Jan 24, 2018 Jan 24, 2018

Copy link to clipboard

Copied

LATEST

In Line 12 there's a semicolon instead of a colon

function btnClick(event:MouseEvent);void {

should be

function btnClick(event:MouseEvent):void {

Votes

Translate

Translate

Report

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