C# to ActionScript tutorial


In this tutorial you will learn what must be done to start developing actionscript applications in c# with the jsc compiler. Jsc enables you to write your code in c# and it will be compiled into actionscript for you.

Post your questions at google groups.
Read my blog at wordpress.
Visit jsc homepage.
View the result of this tutorial.


Written by Arvo Sulakatko 2008 April.

You can skip some steps if you have already installed the software needed.

Step 1: Visual Studio


Install Visual Studio 2008 C# Express Edition. ~60mb




Step 2: Flex


Download Free Adobe Flex SDK. ~75mb

Choose c:\util\flex\ as the target location.

Flex requires Java Runtime. Download and install it.

Step 3: jsc


Download jsc. ~2mb

Choose c:\util\jsc\ as the target location.



Step 4: Project Templates

Copy the project templates from C:\util\jsc\templates\ to My Documents\Visual Studio 2008\Templates\ProjectTemplates\.
In this tutorial we only need OrcasFlashApplication template.





Step 5: New Project


Run Microsoft Visual C# 2008 Express Edition and open the new project dialog and create a new project.



Step 6: Debug Interface Access SDK

UPDATE: jsc can now be compiled without DIA support. To compile with DIA support WITH_DIA conditional constant should be defined.

More about DIA here.

As there seems to be no public download, you should delete all .pdb files at c:\util\jsc\bin\ and disable debug info output. Otherwise jsc will try to load DIA to get variable names and if you do not have DIA installed it will just try to guess.



Step 7: Some fixups

We need to change the tools/mxmlc.bat file to target the installed flex SDK.

We need to change the tools/jsc.bat file to target current project.



Enable Show advanced build configurations option.


Select the Debug build and add a post build event.

Step 8: Build


Build the project.

My output looks like this:

------ Rebuild All started: Project: OrcasFlashApplication1, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:..\..\..\..\..\..\..\util\jsc\bin\ScriptCoreLib.dll /reference:..\..\..\..\..\..\..\util\jsc\bin\ScriptCoreLib.Query.dll /reference:..\..\..\..\..\..\..\util\jsc\bin\ScriptCoreLibA.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug- /filealign:512 /optimize- /out:obj\Debug\OrcasFlashApplication1.dll /resource:web\assets\AlphaTest\Preview.png,OrcasFlashApplication1.web.assets.AlphaTest.Preview.png /resource:web\assets\AlphaTest\rain_1.mp3,OrcasFlashApplication1.web.assets.AlphaTest.rain_1.mp3 /target:library ActionScript\Assets.cs ActionScript\OrcasFlashApplication.cs ActionScript\Extensions.cs Properties\AssemblyInfo.cs IAssemblyReferenceToken.cs

Compile complete -- 0 errors, 0 warnings
OrcasFlashApplication1 -> C:\Users\predator\Documents\Visual Studio 2008\Projects\OrcasFlashApplication1\OrcasFlashApplication1\bin\Debug\OrcasFlashApplication1.dll
pushd ..\..\tools
call build.bat
popd
C# to JavaScript by Arvo Sulakatko 2008
zproxy.wordpress.com, jsc.sourceforge.net
Copyright © 2008, All rights reserved

Current Path: C:\Users\predator\Documents\Visual Studio 2008\Projects\OrcasFlashApplication1\OrcasFlashApplication1\bin\Debug
assembly: file:///c:/util/jsc/bin/ScriptCoreLib.DLL
assembly: file:///c:/util/jsc/bin/ScriptCoreLib.Query.DLL
assembly: file:///C:/Users/predator/Documents/Visual Studio 2008/Projects/OrcasFlashApplication1/OrcasFlashApplication1/bin/Debug/OrcasFlashApplication1.dll
will compile 'c:\util\jsc\bin\ScriptCoreLib.dll'
found 103 types to be compiled
ScriptCoreLib.ActionScript.Extensions.flash.events.__EventDispatcher -> Extensions.flash.events.__EventDispatcher
ScriptCoreLib.ActionScript.BCLImplementation.System.__Object -> BCLImplementation.System.__Object
ScriptCoreLib.ActionScript.BCLImplementation.System.__Exception -> BCLImplementation.System.__Exception
ScriptCoreLib.ActionScript.BCLImplementation.System.__NotSupportedException -> BCLImplementation.System.__NotSupportedException
ScriptCoreLib.ActionScript.BCLImplementation.System.__Math -> BCLImplementation.System.__Math
ScriptCoreLib.ActionScript.Query.InternalSequenceImplementation -> Query.InternalSequenceImplementation
pdb not found c:\util\jsc\bin\ScriptCoreLib.pdb
ScriptCoreLib.ActionScript.BCLImplementation.System.__String -> BCLImplementation.System.__String
ScriptCoreLib.ActionScript.BCLImplementation.System.__NotImplementedException -> BCLImplementation.System.__NotImplementedException
ScriptCoreLib.ActionScript.BCLImplementation.System.__ArgumentNullException -> BCLImplementation.System.__ArgumentNullException
ScriptCoreLib.Shared.Query.SZArrayEnumerator`1 -> Query.SZArrayEnumerator`1
ScriptCoreLib.ActionScript.BCLImplementation.System.Collections.__IEnumerable -> BCLImplementation.System.Collections.__IEnumerable
ScriptCoreLib.ActionScript.BCLImplementation.System.__Random -> BCLImplementation.System.__Random
ScriptCoreLib.ActionScript.BCLImplementation.System.Collections.Generic.__ICollection`1 -> BCLImplementation.System.Collections.Generic.__ICollection`1
ScriptCoreLib.ActionScript.Extensions.flash.text.__TextField -> Extensions.flash.text.__TextField
ScriptCoreLib.ActionScript.BCLImplementation.System.__Action -> BCLImplementation.System.__Action
ScriptCoreLib.ActionScript.BCLImplementation.System.__Action`1 -> BCLImplementation.System.__Action`1
ScriptCoreLib.ActionScript.BCLImplementation.System.__Action`2 -> BCLImplementation.System.__Action`2
ScriptCoreLib.ActionScript.BCLImplementation.System.__Action`3 -> BCLImplementation.System.__Action`3
ScriptCoreLib.ActionScript.Extensions.flash.ui.__ContextMenuItem -> Extensions.flash.ui.__ContextMenuItem
ScriptCoreLib.ActionScript.BCLImplementation.System.Collections.Generic.__IEnumerable`1 -> BCLImplementation.System.Collections.Generic.__IEnumerable`1
ScriptCoreLib.ActionScript.BCLImplementation.System.Text.__StringBuilder -> BCLImplementation.System.Text.__StringBuilder
ScriptCoreLib.ActionScript.BCLImplementation.System.__Delegate -> BCLImplementation.System.__Delegate
ScriptCoreLib.ActionScript.BCLImplementation.System.__IntPtr -> BCLImplementation.System.__IntPtr
ScriptCoreLib.ActionScript.BCLImplementation.System.Collections.Generic.__List`1 -> BCLImplementation.System.Collections.Generic.__List`1
ScriptCoreLib.ActionScript.BCLImplementation.System.Collections.Generic.__List`1+__Enumerator -> BCLImplementation.System.Collections.Generic.__List`1+__Enumerator
ScriptCoreLib.ActionScript.Extensions.flash.display.__DisplayObject -> Extensions.flash.display.__DisplayObject
ScriptCoreLib.ActionScript.BCLImplementation.System.__MulticastDelegate -> BCLImplementation.System.__MulticastDelegate
ScriptCoreLib.ActionScript.BCLImplementation.System.__Convert -> BCLImplementation.System.__Convert
ScriptCoreLib.ActionScript.BCLImplementation.System.Collections.__IEnumerator -> BCLImplementation.System.Collections.__IEnumerator
ScriptCoreLib.ActionScript.Extensions.flash.util.__Timer -> Extensions.flash.util.__Timer
ScriptCoreLib.ActionScript.Extensions.CommonExtensions -> Extensions.CommonExtensions
ScriptCoreLib.ActionScript.Extensions.CommonExtensions+IFill_Dispose -> Extensions.CommonExtensions+IFill_Dispose
ScriptCoreLib.ActionScript.BCLImplementation.System.Collections.Generic.__IList`1 -> BCLImplementation.System.Collections.Generic.__IList`1
ScriptCoreLib.ActionScript.BCLImplementation.System.Collections.Generic.__IEnumerator`1 -> BCLImplementation.System.Collections.Generic.__IEnumerator`1
ScriptCoreLib.ActionScript.Extensions.flash.display.__InteractiveObject -> Extensions.flash.display.__InteractiveObject
ScriptCoreLib.ActionScript.BCLImplementation.System.__IDisposable -> BCLImplementation.System.__IDisposable
actionscript type compiler - 3973ms
will compile 'c:\util\jsc\bin\ScriptCoreLib.Query.dll'
found 137 types to be compiled
ScriptCoreLib.ActionScript.Query.DefinedError -> Query.DefinedError
pdb not found c:\util\jsc\bin\ScriptCoreLib.Query.pdb
ScriptCoreLib.ActionScript.Query.__Enumerable -> Query.__Enumerable
ScriptCoreLib.ActionScript.Query.__Enumerable+_SelectIterator_d__b`2 -> Query.__Enumerable+_SelectIterator_d__b`2
ScriptCoreLib.ActionScript.Query.__Enumerable+_SelectManyIterator_d__37`3 -> Query.__Enumerable+_SelectManyIterator_d__37`3
ScriptCoreLib.ActionScript.Query.__Enumerable+_SelectManyIterator_d__16`2 -> Query.__Enumerable+_SelectManyIterator_d__16`2
ScriptCoreLib.ActionScript.Query.__Enumerable+_RangeIterator_d__91 -> Query.__Enumerable+_RangeIterator_d__91
ScriptCoreLib.ActionScript.Query.__Enumerable+_WhereIterator_d__0`1 -> Query.__Enumerable+_WhereIterator_d__0`1
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions -> Lambda.LambdaExtensions
ScriptCoreLib.ActionScript.Lambda.YFunc`2 -> Lambda.YFunc`2
ScriptCoreLib.ActionScript.Lambda.YFunc`3 -> Lambda.YFunc`3
ScriptCoreLib.ActionScript.Lambda.YAction`1 -> Lambda.YAction`1
ScriptCoreLib.ActionScript.Lambda.YAction`2 -> Lambda.YAction`2
ScriptCoreLib.ActionScript.BCLImplementation.System.__Func`1 -> BCLImplementation.System.__Func`1
ScriptCoreLib.ActionScript.BCLImplementation.System.__Func`2 -> BCLImplementation.System.__Func`2
ScriptCoreLib.ActionScript.BCLImplementation.System.__Func`3 -> BCLImplementation.System.__Func`3
ScriptCoreLib.ActionScript.BCLImplementation.System.__Func`4 -> BCLImplementation.System.__Func`4
ScriptCoreLib.ActionScript.BCLImplementation.System.__Func`5 -> BCLImplementation.System.__Func`5
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass1 -> Lambda.LambdaExtensions+<>c__DisplayClass1
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass4`1 -> Lambda.LambdaExtensions+<>c__DisplayClass4`1
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass7`2 -> Lambda.LambdaExtensions+<>c__DisplayClass7`2
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClassa`3 -> Lambda.LambdaExtensions+<>c__DisplayClassa`3
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClassd`3 -> Lambda.LambdaExtensions+<>c__DisplayClassd`3
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass10`2 -> Lambda.LambdaExtensions+<>c__DisplayClass10`2
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass13`3 -> Lambda.LambdaExtensions+<>c__DisplayClass13`3
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass16`2 -> Lambda.LambdaExtensions+<>c__DisplayClass16`2
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass19`4 -> Lambda.LambdaExtensions+<>c__DisplayClass19`4
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass1c`3 -> Lambda.LambdaExtensions+<>c__DisplayClass1c`3
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass1f`2 -> Lambda.LambdaExtensions+<>c__DisplayClass1f`2
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass22 -> Lambda.LambdaExtensions+<>c__DisplayClass22
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass25`1 -> Lambda.LambdaExtensions+<>c__DisplayClass25`1
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass28`2 -> Lambda.LambdaExtensions+<>c__DisplayClass28`2
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass2b`3 -> Lambda.LambdaExtensions+<>c__DisplayClass2b`3
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass2e`1 -> Lambda.LambdaExtensions+<>c__DisplayClass2e`1
ScriptCoreLib.ActionScript.Lambda.LambdaExtensions+<>c__DisplayClass31`2 -> Lambda.LambdaExtensions+<>c__DisplayClass31`2
actionscript type compiler - 3511ms
will compile 'C:\Users\predator\Documents\Visual Studio 2008\Projects\OrcasFlashApplication1\OrcasFlashApplication1\bin\Debug\OrcasFlashApplication1.dll'
found 138 types to be compiled
pdb not found C:\Users\predator\Documents\Visual Studio 2008\Projects\OrcasFlashApplication1\OrcasFlashApplication1\bin\Debug\OrcasFlashApplication1.pdb
OrcasFlashApplication1.ActionScript.OrcasFlashApplication1
actionscript type compiler - 176ms
- OrcasFlashApplication1
Loading configuration file C:\util\flex\frameworks\flex-config.xml
Recompile: C:\Users\predator\Documents\Visual Studio 2008\Projects\OrcasFlashApplication1\OrcasFlashApplication1\bin\Debug\web\OrcasFlashApplication1\ActionScript\OrcasFlashApplication1.as
Reason: The source file or one of the included files has been updated.
Files changed: 1 Files affected: 0
OrcasFlashApplication1.swf (936 bytes)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Step 9: Test with flash player


Open your OrcasFlashApplication1.swf with C:\util\flex\runtimes\player\win\FlashPlayer.exe.

Step 10: Write Some New Code

Create just a textfield and attach an event which will display hello world. Then build your project.


Test it with flash player.



Click on the text.

Watch it online here.