How to build SWF without main function in actionscript?

View: New views
6 Messages — Rating Filter:   Alert me  

How to build SWF without main function in actionscript?

by Selene Platt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am new to mtasc and cannot find an answer to this question.  I have an
actionscript file that used to be straight code, compiled into a SWF via a
FLA.  The SWF is embedded in the document via document.writes done by a
javascript file. Now that I'm implementing mtasc to auto-build it, I seem to
be forced to use an object-oriented approach and wrap my code in a function
definition, and also define a main() function.  It's not working and I can't
figure out why or what's really required. I would like to know:

(a) Can I retain my code's original structure w/o any function declarations
and have mtasc successfully compile it? (currently I'm getting compile
errors w/o the function declaration)
(b) If not (a), can I simply wrap my code in a function w/o main()?
(c) If neither, and I must include main(), what is the exact syntax assuming
I have several input arguments?

In any case, I also need to know if there's any difference in how I call the
SWF from the JS code, and also what the corresponding mtasc cmd line would
look like.  Thanks very much,

Selene


--
MTASC : no more coffee break while compiling

Re: How to build SWF without main function in actionscript?

by J.F. Groff :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

+1, I got the exact same problem. Tried to add main() as in good old C
code but mtasc still refused to compile and I couldn't find a howto
guide for converting fla-based code to mtasc-digestable code.

Note: I'm coming from the Unix world and have never even used
Macromedia's own compiler, my graphics colleagues do that. However I
do help them program ActionScript stuff and this is the process we
need to automate.

Thanks to any kind soul on the list for help. I'm ready to send you a
sample of our .as files in private message if needed.

  JFG

On Dec 14, 2007 11:14 PM, Selene Platt <selene@...> wrote:

> I am new to mtasc and cannot find an answer to this question.  I have an
> actionscript file that used to be straight code, compiled into a SWF via a
> FLA.  The SWF is embedded in the document via document.writes done by a
> javascript file. Now that I'm implementing mtasc to auto-build it, I seem to
> be forced to use an object-oriented approach and wrap my code in a function
> definition, and also define a main() function.  It's not working and I can't
> figure out why or what's really required. I would like to know:
>
> (a) Can I retain my code's original structure w/o any function declarations
> and have mtasc successfully compile it? (currently I'm getting compile
> errors w/o the function declaration)
> (b) If not (a), can I simply wrap my code in a function w/o main()?
> (c) If neither, and I must include main(), what is the exact syntax assuming
> I have several input arguments?
>
> In any case, I also need to know if there's any difference in how I call the
> SWF from the JS code, and also what the corresponding mtasc cmd line would
> look like.  Thanks very much,
>
> Selene
>
>
> --
> MTASC : no more coffee break while compiling
>

--
MTASC : no more coffee break while compiling

Re: How to build SWF without main function in actionscript?

by Ralf Bokelberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Generally MTASC works with AS2 code only.
It is not able to translate AS1 code or AS2-ish timeline code.

If you have some code on the timeline, it is implicitely referencing _root.
If you move this code into a public static main function, you have to make
these implicit references explicit.

a = 4
b = 5
c = a * b

class MainClass
{
   public static function main( root : MovieClip )
   {
         root.a = 4;
         root.b = 5;
         root.c = root.a * root.b;
   }
}

If you only need to change some values like a string, a number
or a url in your code, you could maybe get away with using swfmill.
Use swfmill  to export your swf as xml. From there you can automate
the changes to the xml and the creation of the swf using swfmill and a
build tool like ant.

Cheers
Ralf.

On Dec 15, 2007 12:34 AM, J.F. Groff <jfgroff@...> wrote:

> +1, I got the exact same problem. Tried to add main() as in good old C
> code but mtasc still refused to compile and I couldn't find a howto
> guide for converting fla-based code to mtasc-digestable code.
>
> Note: I'm coming from the Unix world and have never even used
> Macromedia's own compiler, my graphics colleagues do that. However I
> do help them program ActionScript stuff and this is the process we
> need to automate.
>
> Thanks to any kind soul on the list for help. I'm ready to send you a
> sample of our .as files in private message if needed.
>
>   JFG
>
>
> On Dec 14, 2007 11:14 PM, Selene Platt <selene@...> wrote:
> > I am new to mtasc and cannot find an answer to this question.  I have an
> > actionscript file that used to be straight code, compiled into a SWF via a
> > FLA.  The SWF is embedded in the document via document.writes done by a
> > javascript file. Now that I'm implementing mtasc to auto-build it, I seem to
> > be forced to use an object-oriented approach and wrap my code in a function
> > definition, and also define a main() function.  It's not working and I can't
> > figure out why or what's really required. I would like to know:
> >
> > (a) Can I retain my code's original structure w/o any function declarations
> > and have mtasc successfully compile it? (currently I'm getting compile
> > errors w/o the function declaration)
> > (b) If not (a), can I simply wrap my code in a function w/o main()?
> > (c) If neither, and I must include main(), what is the exact syntax assuming
> > I have several input arguments?
> >
> > In any case, I also need to know if there's any difference in how I call the
> > SWF from the JS code, and also what the corresponding mtasc cmd line would
> > look like.  Thanks very much,
> >
> > Selene
> >
> >
> > --
> > MTASC : no more coffee break while compiling
> >
>
> --
> MTASC : no more coffee break while compiling
>



--
Ralf Bokelberg <ralf.bokelberg@...>
Flex & Flash Consultant based in Cologne/Germany

--
MTASC : no more coffee break while compiling

Parent Message unknown How to build SWF without main function in actionscript?

by Selene Platt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not sure if the previous posts answer my question.  Below is the code
from my .as file.  Originally, I had an .fla file containing this script
which was then compiled into a .swf; it's ActionScript 2.0.  Also, the
original version started with the 'if' statement; the class/var/function
defs needed to be added to support mtasc, as was the main function at the
bottom.  Thus, the embedded swf all simply jumped right into the code. The
the vars 'cleq_*' declared below are input params in the swf call.  What's
happening is that the swf gets invoked but nothing happens..the code does
not execute.  I've tried all sorts of combinations with the main function
and how I pass the params but nothing seems to work..I'm guessing it's
simply a syntax issue, but being totally new to mtasc and with no specific
examples that are like my case, I'm not sure what to do.

Any help would be greatly appreciated! -- S.
---------------------
import flash.external.ExternalInterface;

class Cleq {

      static var app : Cleq;

      function Cleq() {
        var ret_uid = "";
        var cleq_op, cleq_clientkey, cleq_uuid;

        if (cleq_op == "set") {
            if ((cleq_clientkey != null) && (cleq_uuid != null)) {
        // see if the flash cookie object exists
        var cleqFO = SharedObject.getLocal(cleq_clientkey);
        if (cleqFO.data.uid != null) {
            // cookie already exists, return the stored UUID value
            ret_uid = cleqFO.data.uid;
        } else {
            // cookie doesn't exist, store and return the UUID value if
successful,
            // otherwise return "null"
            // CHANGED to always return input UUID if FO didn't already
exist,
            // regardless of whether we can store it
            cleqFO.data.uid = cleq_uuid;
            cleqFO.flush();
            ret_uid = cleq_uuid;
        }
    }
    // call the 9.js javascript function that sets the cookie
    var myCookieURL = "javascript:setCleqID('"+ret_uid+"')";
    getURL(myCookieURL);
    } else if (cleq_op == "del") {
        // remove flash cookie file
        var cleqFO = SharedObject.getLocal(cleq_clientkey);
        var ret_val;
        if (cleqFO != null) {
            cleqFO.clear();
        } else {
            ret_val = "Flash cookie file for "+cleq_clientkey+" does not
exist";
        }
var myCookieURL = "javascript:delCleqID('"+ret_val+"')";
getURL(myCookieURL);
}
}
    static function main(mc) {
        app = new Cleq();
        }
}


--
MTASC : no more coffee break while compiling

Re: How to build SWF without main function in actionscript?

by Ralf Bokelberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Selene

as i wrote in my previous post, you need to replace the implicit references
to root by explicit ones. The mc parameter of public static main is a reference
to root, so you can use it inside your class to achieve that.

Here is the code (of cause untested )

import flash.external.ExternalInterface;

class Cleq
{
       
        public static function main( root )
        {
                if (root.cleq_op == "set") {

                        var ret_uid : String = "";

                        if ((root.cleq_clientkey != null) && (root.cleq_uuid != null)) {
                                // see if the flash cookie object exists
                                var cleqFO = SharedObject.getLocal(root.cleq_clientkey);
                                if (cleqFO.data.uid != null) {
                                        // cookie already exists, return the stored UUID value
                                        ret_uid = cleqFO.data.uid;
                                } else {
                                        // cookie doesn't exist, store and return the UUID value if successful,
                                        // otherwise return "null"
                                        // CHANGED to always return input UUID if FO didn't already exist,
                                        // regardless of whether we can store it
                                        cleqFO.data.uid = root.cleq_uuid;
                                        cleqFO.flush();
                                        ret_uid = root.cleq_uuid;
                                }
                        }
                        // call the 9.js javascript function that sets the cookie
                        var myCookieURL = "javascript:setCleqID('"+ret_uid+"')";
                        getURL(myCookieURL);
                       
                } else if (root.cleq_op == "del") {
                        // remove flash cookie file
                        var cleqFO = SharedObject.getLocal( root.cleq_clientkey );
                        var ret_val : String = "";
                        if (cleqFO != null) {
                                cleqFO.clear();
                        } else {
                                ret_val = "Flash cookie file for "+root.cleq_clientkey+" does not exist";
                        }
                        var myCookieURL = "javascript:delCleqID('"+ret_val+"')";
                        getURL(myCookieURL);
                }
        }
}

Cheers
Ralf.


On Dec 16, 2007 2:45 PM, Selene Platt <selene@...> wrote:

> I'm not sure if the previous posts answer my question.  Below is the code
> from my .as file.  Originally, I had an .fla file containing this script
> which was then compiled into a .swf; it's ActionScript 2.0.  Also, the
> original version started with the 'if' statement; the class/var/function
> defs needed to be added to support mtasc, as was the main function at the
> bottom.  Thus, the embedded swf all simply jumped right into the code. The
> the vars 'cleq_*' declared below are input params in the swf call.  What's
> happening is that the swf gets invoked but nothing happens..the code does
> not execute.  I've tried all sorts of combinations with the main function
> and how I pass the params but nothing seems to work..I'm guessing it's
> simply a syntax issue, but being totally new to mtasc and with no specific
> examples that are like my case, I'm not sure what to do.
>
> Any help would be greatly appreciated! -- S.
> ---------------------
> import flash.external.ExternalInterface;
>
> class Cleq {
>
>       static var app : Cleq;
>
>       function Cleq() {
>         var ret_uid = "";
>         var cleq_op, cleq_clientkey, cleq_uuid;
>
>         if (cleq_op == "set") {
>             if ((cleq_clientkey != null) && (cleq_uuid != null)) {
>         // see if the flash cookie object exists
>         var cleqFO = SharedObject.getLocal(cleq_clientkey);
>         if (cleqFO.data.uid != null) {
>             // cookie already exists, return the stored UUID value
>             ret_uid = cleqFO.data.uid;
>         } else {
>             // cookie doesn't exist, store and return the UUID value if
> successful,
>             // otherwise return "null"
>             // CHANGED to always return input UUID if FO didn't already
> exist,
>             // regardless of whether we can store it
>             cleqFO.data.uid = cleq_uuid;
>             cleqFO.flush();
>             ret_uid = cleq_uuid;
>         }
>     }
>     // call the 9.js javascript function that sets the cookie
>     var myCookieURL = "javascript:setCleqID('"+ret_uid+"')";
>     getURL(myCookieURL);
>     } else if (cleq_op == "del") {
>         // remove flash cookie file
>         var cleqFO = SharedObject.getLocal(cleq_clientkey);
>         var ret_val;
>         if (cleqFO != null) {
>             cleqFO.clear();
>         } else {
>             ret_val = "Flash cookie file for "+cleq_clientkey+" does not
> exist";
>         }
> var myCookieURL = "javascript:delCleqID('"+ret_val+"')";
> getURL(myCookieURL);
> }
> }
>     static function main(mc) {
>         app = new Cleq();
>         }
> }
>
>
> --
> MTASC : no more coffee break while compiling
>



--
Ralf Bokelberg <ralf.bokelberg@...>
Flex & Flash Consultant based in Cologne/Germany

--
MTASC : no more coffee break while compiling

Re: How to build SWF without main function in actionscript?

by Selene Platt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ralf - thank you so much for the further explanation; I am new at this and
appreciated it.  Your solution works perfectly!

Selene


--
MTASC : no more coffee break while compiling