Article:
  ActionScript for Non-Coders
Subject:   Flash MX files
Date:   2004-09-03 02:42:51
From:   Sham_B
I have put Flash MX versions of the files for this article in a zip available at http://www.futuremedia.org.uk/ORA/FMX_files.zip, (350k)and will hopefully add a http://www.futuremedia.org.uk/ORA/F5_files.zip (Flash 5 version) in the next couple of days. I dont intend to do a Flash 4 version :D


Because of requests for Flash MX compatible hack files for the Flash Hacks book, they are now available for download as well as the Flash MX 2004 files. You can download the Flash MX zip (10.4Mb) at http://examples.oreilly.com/flashhks/


This means that the Flash Hacks book now fully supports Flash MX as well as Flash MX 2004.


S

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • Flash MX files
    2004-09-14 03:09:10  garylarrson [View]

    If you are still working on a flash 5 version i am sorry to be annoying, but i would love to be able to get my hands on the camera but at this moment in time i dont know much about actionscript and the link to the file doesnt work

    my appoligies again,

    gary
    • Flash MX files
      2004-09-28 07:58:55  Sham_B [View]

      whoops. I will upload it today, so it should be up within a few hours of this post.

      S
      • Flash MX files
        2004-09-28 11:03:14  Sham_B [View]

        the Flash 5 compatible file is now up at http://www.futuremedia.org.uk/ORA/F5_files.zip.

        Flash 5 doesnt support the Stage class, which the camera uses, so instead you need to define two variables on frame 1 of the main timeline as follows:

        // These lines MUST be in the root timeline.
        // Equate them to the stage width and height
        // (Control+M or double-click on the frame rate
        // value below the timeline to see them).
        //
        stageWidth = 720;
        stageHeight = 480;

        You also have to copy across the movie clips camFrame AND dummy into any FLA you want to use the v-cam in (the reason you need dummy is noted below).

        The other problem with Flash 5 is that it doesnt support Flash MX/Flash MX2004 style events (i.e. JavaScript style callbacks), which I guess would be the main problem in converting the code over to Flash 5. Here's how I've solved this issue (there are other ways to do this, but this code keeps the script looking as much like the Flash MX 2004 version as possible).

        In the camera, there is a second movie clip called dummy. Attached to this movie clip is the following code...

        onClipEvent (load) {
        // Initialize the v-cam...
        //
        // target and camera are the paths to the
        // controlled timeline and camera clip respectively.
        target = _parent._parent;
        cam = _parent;
        // make camera frame invisible
        cam._visible = false;
        // Capture stage parameters
        sX = _root.stageWidth;
        sY = _root.stageHeight;
        cX = sX/2;
        cY = sY/2;
        // create color instances for color
        // transforms (if any).
        camColor = new Color(cam);
        parentColor = new Color(target);
        }
        onClipEvent (enterFrame) {
        // Make the stage move so that the
        // v-cam is centered on the
        // viewport every frame
        parentColor.setTransform(camColor.getTransform());
        scaleX = sX/_parent._width;
        scaleY = sY/_parent._height;
        target._x = cX-(cam._x*scaleX);
        target._y = cY-(cam._y*scaleY);
        target._xscale = 100*scaleX;
        target._yscale = 100*scaleY;
        }
        onClipEvent (unload) {
        // If the v-cam is ever removed (unloaded)
        // the stage, return the stage to the default
        // settings.
        resetTrans = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
        parentColor.setTransform(resetTrans);
        target._xscale = 100;
        target._yscale = 100;
        target._x = 0;
        target._y = 0;
        }

        This is essentially the same code as the MX 2004 code, except that I use the onLoad to initialize the camera (in the MX 2004 this is done via a script on frame 1 of the camera timeline).

        I've only tested the Flash 5 version for a short while, but it seems okay.

        Remember, to see the finished effect, test the SWF in the browser (F12) rather than in test mode (Control+F12).

        HTH

        S