Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/flash/display/ShaderData.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package flash.display {


import flash.utils.ByteArray;


/**
* @externs
*/
final public dynamic class ShaderData {


public function ShaderData (byteArray:ByteArray) {}


}


}
53 changes: 53 additions & 0 deletions lib/flash/net/URLVariables.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package flash.net {


/**
* @externs
* The URLVariables class allows you to transfer variables between an
* application and a server. Use URLVariables objects with methods of the
* URLLoader class, with the `data` property of the URLRequest
* class, and with flash.net package functions.
*/
public dynamic class URLVariables {


/**
* Creates a new URLVariables object. You pass URLVariables objects to the
* `data` property of URLRequest objects.
*
* If you call the URLVariables constructor with a string, the
* `decode()` method is automatically called to convert the string
* to properties of the URLVariables object.
*
* @param source A URL-encoded string containing name/value pairs.
*/
public function URLVariables (source:String = null) {}


/**
* Converts the variable string to properties of the specified URLVariables
* object.
*
* This method is used internally by the URLVariables events. Most users
* do not need to call this method directly.
*
* @param source A URL-encoded query string containing name/value pairs.
* @throws Error The source parameter must be a URL-encoded query string
* containing name/value pairs.
*/
public function decode (source:String):void {}


/**
* Returns a string containing all enumerable variables, in the MIME content
* encoding _application/x-www-form-urlencoded_.
*
* @return A URL-encoded string containing name/value pairs.
*/
public function toString ():String { return null; }


}


}
10 changes: 10 additions & 0 deletions lib/flash/net/navigateToURL.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flash.net {


/**
* @externs
*/
public function navigateToURL (request:URLRequest, window:String = null):void {}


}
10 changes: 10 additions & 0 deletions lib/flash/net/sendToURL.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flash.net {


/**
* @externs
*/
public function sendToURL (request:URLRequest):void {}


}
34 changes: 34 additions & 0 deletions lib/flash/utils/utils/Dictionary.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package flash.utils {


/**
* @externs
*/
public dynamic class Dictionary {


public function Dictionary (weakKeys:Boolean = false) {}
// public function exists (key:*):Boolean { return false; }
// public function get (key:K):V { return null; }
// public function remove (key:*):Boolean { return false; }
// public function set (key:K, value:V):V { return null; }


// public inline function iterator ():Iterator<K> {

// return this.keys ();

// }


// public inline function each ():Iterator<V> {

// return this.iterator ();

// }


}


}
10 changes: 10 additions & 0 deletions lib/flash/utils/utils/clearTimeout.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flash.utils {


/**
* @externs
*/
public function clearTimeout (id:uint):void {}


}
10 changes: 10 additions & 0 deletions lib/flash/utils/utils/getDefinitionByName.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flash.utils {


/**
* @externs
*/
public function getDefinitionByName (name:String):* { return null; }


}
10 changes: 10 additions & 0 deletions lib/flash/utils/utils/getQualifiedClassName.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flash.utils {


/**
* @externs
*/
public function getQualifiedClassName (value:*):String { return null; }


}
10 changes: 10 additions & 0 deletions lib/flash/utils/utils/getQualifiedSuperclassName.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flash.utils {


/**
* @externs
*/
public function getQualifiedSuperclassName (value:*):String { return null; }


}
10 changes: 10 additions & 0 deletions lib/flash/utils/utils/getTimer.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flash.utils {


/**
* @externs
*/
public function getTimer ():Number { return 0; }


}
10 changes: 10 additions & 0 deletions lib/flash/utils/utils/setTimeout.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flash.utils {


/**
* @externs
*/
public function setTimeout (closure:Function, delay:Number, ...arguments):uint { return 0; }


}
8 changes: 7 additions & 1 deletion lib/openfl/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
const openfl = {

desktop: require("./desktop"),

Expand Down Expand Up @@ -323,3 +323,9 @@ module.exports = {
Vector: require("./Vector").default,

}

module.exports = openfl;
if(typeof window !== "undefined")
{
window.flash = openfl;
}
33 changes: 33 additions & 0 deletions scripts/AS3ExternsGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import haxe.macro.Type;
import haxe.macro.Type.BaseType;
import haxe.macro.Type.AbstractType;
import haxe.macro.Context;
using StringTools;

class AS3ExternsGenerator {
private static final ALWAYS_ALLOWED_REFERENCE_TYPES = [
Expand Down Expand Up @@ -1199,6 +1200,32 @@ class AS3ExternsGenerator {
var fileOutput = File.write(outputFilePath);
fileOutput.writeString(generated);
fileOutput.close();
if (options != null && options.remapPackages != null) {
var shouldWriteAgain = false;
var remapPackages = options.remapPackages;
var i = 0;
while (i < remapPackages.length) {
var originalName = remapPackages[i];
i++;
var newName = remapPackages[i];
i++;
if (outputFilePath.contains("/lib/" + originalName + "/")) {
shouldWriteAgain = true;
outputFilePath = outputFilePath.replace("/lib/" + originalName + "/", "/lib/" + newName + "/");
}
if (generated.contains(originalName)) {
Copy link
Copy Markdown
Member

@joshtynjala joshtynjala Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing a replace over the entire file contents using the package name only feels dangerous. It could lead to things getting replaced that shouldn't be replaced. If someone wanted to use this option to remap "com", that would not work as well as "openfl", which is probably safer as long as things are case-sensitive. I've been trying to write the generators in a way that they might be useful to other projects too.

A safer version might be to replace "package " + originalName and ":" + originalName. Or maybe regular expressions, to handle potential whitespace variations and things.

// for AS3
new EReg("package\\s+" + originalName + "(?=\\.|\\s*{)", "g");
new EReg(":\\s+" + originalName + "(?=\\.)", "g");

However, even with this approach, doc comments may still include some replacements. There may not be a way to avoid that without calling the generator twice and remapping at an earlier stage of the process.

Not as important, but just something I that came to mind. I assume that this is inspired by Haxe's --remap option. I wonder if --remap supports sub-packages, like --remap com.example:org.example. It would be good to either support that, or to throw an exception if a . character is contained in either the original or new name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using regular expressions may be the solution here, I feel like if an good approach for manipulating the end generated file could be cleaner
I am not sure about the subpackages.
Should I just try using the eregs?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just try using the eregs?

Yeah, go for it.

I realized that you might need one for imports too.

new EReg("import\\s+" + originalName + "(?=\\.)", "g");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally committed!

shouldWriteAgain = true;
generated = generated.replace(originalName, newName);
}
}
if(shouldWriteAgain)
{
FileSystem.createDirectory(Path.directory(outputFilePath));
fileOutput = File.write(outputFilePath);
fileOutput.writeString(generated);
fileOutput.close();
}
}
}

private function getFileOutputPath(dirPath:String, baseType:BaseType):String {
Expand Down Expand Up @@ -1273,6 +1300,12 @@ typedef AS3GeneratorOptions = {
**/
?renameSymbols:Array<String>,

/**
Remaps a package to another one. Alternates between the original package
name and its new name.
**/
?remapPackages:Array<String>,

/**
Optionally exclude specific symbols.
**/
Expand Down
33 changes: 33 additions & 0 deletions scripts/TSExternsGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import haxe.macro.Type;
import haxe.macro.Type.BaseType;
import haxe.macro.Type.AbstractType;
import haxe.macro.Context;
using StringTools;

class TSExternsGenerator {
private static final ALWAYS_ALLOWED_REFERENCE_TYPES = [
Expand Down Expand Up @@ -1540,6 +1541,32 @@ class TSExternsGenerator {
var fileOutput = File.write(outputFilePath);
fileOutput.writeString(generated);
fileOutput.close();
if (options != null && options.remapPackages != null) {
var shouldWriteAgain = false;
var remapPackages = options.remapPackages;
var i = 0;
while (i < remapPackages.length) {
var originalName = remapPackages[i];
i++;
var newName = remapPackages[i];
i++;
if (outputFilePath.contains("/lib/" + originalName + "/")) {
shouldWriteAgain = true;
outputFilePath = outputFilePath.replace("/lib/" + originalName + "/", "/lib/" + newName + "/");
}
if (generated.contains(originalName)) {
shouldWriteAgain = true;
generated = generated.replace(originalName, newName);
}
}
if(shouldWriteAgain)
{
FileSystem.createDirectory(Path.directory(outputFilePath));
fileOutput = File.write(outputFilePath);
fileOutput.writeString(generated);
fileOutput.close();
}
}
}

private function getFileOutputPath(dirPath:String, baseType:BaseType):String {
Expand Down Expand Up @@ -1605,6 +1632,12 @@ typedef TSGeneratorOptions = {
**/
?renameSymbols:Array<String>,

/**
Remaps a package to another one. Alternates between the original package
name and its new name.
**/
?remapPackages:Array<String>,

/**
Optionally exclude specific symbols.
**/
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
-D commonjs
-D howlerjs
-D webgl1
--macro AS3ExternsGenerator.generate({outputPath: "../lib", includedPackages: ["openfl"], allowedPackageReferences: [], renameSymbols: ["openfl.VectorData", "openfl.Vector", "openfl.utils.ByteArrayData", "openfl.utils.ByteArray", "lime.app.Future", "openfl.utils.Future"]})
--macro AS3ExternsGenerator.generate({outputPath: "../lib", includedPackages: ["openfl"], allowedPackageReferences: [], remapPackages: ["openfl", "flash"], renameSymbols: ["openfl.VectorData", "openfl.Vector", "openfl.utils.ByteArrayData", "openfl.utils.ByteArray", "lime.app.Future", "openfl.utils.Future"]})
--macro TSExternsGenerator.generate({outputPath: "../lib", includedPackages: ["openfl"], allowedPackageReferences: [], renameSymbols: ["openfl.VectorData", "openfl.Vector", "openfl.utils.ByteArrayData", "openfl.utils.ByteArray", "lime.app.Future", "openfl.utils.Future"]})
--no-inline