Skip to main content
Inspiring
October 25, 2011
Answered

AS3: Include AS file plz help!

  • October 25, 2011
  • 1 reply
  • 1845 views

Hi hope some one can help me with this.

Im trying to include an .as file but i want the path to that file to have a variable.

public var folderpath:String = "english"

include "F:/folder/folder" + folderpath + "/file.as"

is there a way to do this?

Thx pavel

This topic has been closed for replies.
Correct answer Peter Celuch

Include is a compile time directive, you can't use actionscript (which runs after compilation) to affect it.

However, you can use conditional compilation. I can imagine this making sense when you have tons of files at different places and wat to be able to switch between them.

You can define compile time constants in Publish Settings -> ActionScript 3.0 Settings -> Config Constants -> Add as much constants as you need, in this case:

CONFIG::ENGLISH     true

CONFIG::GERMAN     false

CONFIG::ENGLISH function init() { include "en/file.as"; }

CONFIG::GERMAN function init() { include "de/file.as"; }

init();

Result: "en/file.as" gets included.

Conditional compilation enables you to define multiple function or class definitions and with setting the Config constant, you get different results.

1 reply

Peter Celuch
Peter CeluchCorrect answer
Legend
October 30, 2011

Include is a compile time directive, you can't use actionscript (which runs after compilation) to affect it.

However, you can use conditional compilation. I can imagine this making sense when you have tons of files at different places and wat to be able to switch between them.

You can define compile time constants in Publish Settings -> ActionScript 3.0 Settings -> Config Constants -> Add as much constants as you need, in this case:

CONFIG::ENGLISH     true

CONFIG::GERMAN     false

CONFIG::ENGLISH function init() { include "en/file.as"; }

CONFIG::GERMAN function init() { include "de/file.as"; }

init();

Result: "en/file.as" gets included.

Conditional compilation enables you to define multiple function or class definitions and with setting the Config constant, you get different results.

pa-pavelAuthor
Inspiring
November 2, 2011

Hey Peter,

Thank for the reply sorry that I took forever to get back to this. I really appriciate your help

thx pavel