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

As3 - How To Check What IDE the SWF is Running From with Code?

New Here ,
Jul 04, 2014 Jul 04, 2014

Hello, I know this is kind of a strange thing to I want to find, but here is a little backstory as to why I'm trying to do this:

I am making an online multiplayer flash game. I am using flash builder and flash professional for writing as3 and working with graphics. I am also running a development server (by playerio in visual studio ultimate). The way I am testing this online multiplayer game is by running the swf once from flash professional and once from flash builder. They are both connected to the exact same action script 3 code and flash movie clips (via a swc file). I like this setup a lot because flash pro and flash builder each have their own little output area, and I can see the debugging output for each user separately.

The Problem

Although the two swf's are running the exact same code, I want them to behave differently. For example, the flash pro version gets a reference to the image from:

    _gameOverPopup = this["gameOverPopup"];

and the flash builder user gets it like this:

    _gameOverPopup = new GameOverPopup;

There are many other differences as well. For example, I am automatically authenticating and logging in with a different user in each case by just hardcoding username and password in. So now my code looks something like this:

    if (inFlashBuilder) {

         // this only happens when debugging in Flash Builder

         authenticateWith("billyboy", "Secret123");

    }

    else {

         // this only happens when debugging in Flash Professional

         authenticateWith("joeshmoe", "password1");

    } 

This works great, but I am manually changing the inFlashBuilder variable in my code. I basically just have it at the top of the class:

    private var inFlashBuilder:Boolean = true;

and I have to manually changing it from true to false each time before I compile. Oh man, I wish there were a method in System or something like that which I could use control this flag variable. If only...

TOPICS
ActionScript
707
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 ,
Jul 04, 2014 Jul 04, 2014

you can use conditional compiling.  this is an excerpt from Flash Game Development

To define the compilation constants, click File > Publish Settings > ActionScript 3.0 Settings > Config constants. (See Fig11-16.)

Fig11-16.gif

               [Config constants panel where you define conditional compilation constants.]

Click the Add config constant icon (plus sign) and change CONFIG::CONFIG_CONST to CONFIG::AIR. Then double click the value column next to CONFIG::AIR and type false.  Likewise, add CONFIG::WEB and assign a value of true. Obviously, if you want to publish an AIR version, assign opposite values to those two constants.

in your code, the following block will compile only if CONFIG:AIR is true in the settings panel

CONFIG::AIR{

// do whatever

}

and the code in this block will not compile if CONFIG::WEB is false.

CONFIG::WEB{

// do whatever else

}

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
New Here ,
Jul 04, 2014 Jul 04, 2014

Hey, thanks alot. This works great. In order to not cause errors publishing from flash builder I also had to add the config constants there. But that's just in Project -> Properties -> Actionscript Compiler

Then I added this:

-define=CONFIG::IN_FLASH_PROFESSIONAL,false

Screen Shot 2014-07-04 at 8.59.19 PM.png

Then in Flash Pro Actionscript 3 settings I made it true:

Screen Shot 2014-07-04 at 8.41.54 PM.png

woohoo!

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
New Here ,
Jul 04, 2014 Jul 04, 2014

Just to let every know "else" doesn't work with config constants. But you can still do flash builder only things with 1 config constant with the ! operator

CONFIG::IN_FLASH_PROFESSIONAL

{

      // happens only in flash pro

}

!CONFIG::IN_FLASH_PROFESSIONAL

{

     // happens only in flash builder

}

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 ,
Jul 04, 2014 Jul 04, 2014
LATEST

you're welcome.

p.s. please mark helpful/correct responses.

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