Translating AS2 into AS3

Hi, I am trying to create a scrollbar for a movie using a
tutorial I found online (
http://www.flashkit.com/tutorials/Interactivity/Scrollin-Jake_Gel-683/index.php).
My problem is that I am new and am having issues translating the
AS2 script into AS3. Is there anyone who could help me translate
this:
onClipEvent (load) {
diff_y = bound_box._height-scroller._height;
bounds = bound_box.getBounds(this);
top = bounds.yMin+(scroller._height/2);
bottom = bounds.yMax-(scroller._height/2);
function updateScrollbar () {
content._y =
-(((scroller._y-top)/diff_y)*(content._height-bound_box._height));
onClipEvent (mouseDown) {
if (scroller.hitTest(_root._xmouse, _root._ymouse)) {
startDrag ("scroller", false, scroller._x, top, scroller._x,
bottom);
scrolling = true;
// here we stop the drag and set scrolling to false
onClipEvent (mouseUp) {
stopDrag ();
scrolling = false;
onClipEvent (enterFrame) {
if (scrolling) {
updateScrollbar();

you have a 4 enterframe loops running continually when they
only need to run after a menu item has been clicked and can stop
after all menu items have reached their final positions.
and you need to compute the final positions for each menu
item after one of them is clicked.
you might do better to check for an as3 tutorial for an
accordian menu. it's a bit more involved than you're thinking.

Similar Messages

  • Could someone help me "translate" as2 to as3

    Hi, this is my first post i am sorry if this is in the wrong
    cattegory
    Here is the problem. i basically am quite familiar with as2,
    but im not sure how to convert this into as3. Here are the problems
    AS2:
    stop();
    AS2 Version:
    this.x_mc.onRelease = function(){
    gotoAndPlay ("x");
    AS2:
    this.x_mc.onPress= function(){
    gotoAndPlay ("x");
    AS2:
    this.x_mc.onRollOver= function(){
    gotoAndPlay ("x");
    AS2:
    this.x_mc.onRollOut = function(){
    gotoAndPlay ("x");
    Hopefully someone could provide me with the Actionscript 3
    versions of these please. Your help is greatly appreciated, its for
    a Portfolio.

    under 3 we use the event listener model, so you have to set
    up mouse handlers like this:
    function methodname(e:MouseEvent):void {
    //actions
    instancename.addEventListener(MouseEvent.CLICK, methodname);
    set up one event listener and one corresponding handler
    method for each type of mouse event:
    MouseEvent.ROLL_OVER = onRollOver
    MouseEvent.ROLL_OUT = onRollOut
    MouseEvent.MOUSE_DOWN = onPress
    MouseEvent.MOUSE_UP = onRelease
    stop() and gotoAndPlay() remain the same as under 2
    but there is an additional advantage, you can set up a
    'single' event handler for multiple buttons, and then you can use
    the properties of the event Object (ie. 'e' in the above example)
    to access the instance that sent the event notification. for
    instance, say you wanted to change the alpha property of the button
    on rollover you can target the instance using:
    function methodname(e:MouseEvent):void {
    e.target.alpha = 0.5;
    }

  • Translating AS2 to AS3

    Hi.
    Below I have a bit of code that determines the bandwidth that a user has.  It is written in ActionScript 2.  The problem is that I am unfamiliar with AS2, and I wanted to use this in conjunction with a live streaming video player built in AS3.  I was wondering if anyone could give me the equivalent code in AS3, or if there's any way to tell flash that a portion of the code will be written in AS2.
    Thank You,
    Ari Amiri
    nc = new NetConnection();
    nc.onStatus = function(info) {
        trace("Level: "+info.level+" Code: "+info.code);
        if (info.code == "NetConnection.Connect.Success") {
            trace("--- connected to: " + this.uri);
    nc.onBWDone = function(kbitDown, deltaDown, deltaTime, latency) {
        trace("onBWDone: kbitDown:"+kbitDown+" deltaDown:"+deltaDown+" deltaTime:"+deltaTime+" latency:"+latency);
        // app logic based on the bandwidth detected follows here
        detected_bw = kbitDown;
        // close the Netconnection to bwcheck
        this.close();
    nc.onBWCheck = function() {
        trace("onBWCheck");
        return ++counter; // Serverside, just ignore any return value, For now return the call count
    nc.connect("rtmp://216.18.231.42/bwcheck", true);
    stop();

    Thanks kglad. However, my preloader doesn't seem to work
    quite properly. The graphic that I want to fill up as the movie
    loads does not appear for a while, then suddenly fills up and just
    sits there for a while until the movie is displayed. Do you know
    why this might be?

  • Need help translating menu from as2 to as3

    Ive been at this for a week now, trying to build a
    straightforward accordian menu, translating an existing as2 menu
    into as3. I desperately need help, I've reach my conceptual ends in
    terms of code knowledge. Could someone please take a look at what
    I've got and what I need to do to get it working? I've included the
    AS3 file I've been working on and well as the AS2 files I've been
    referencing and attempting to translate. Any help really be
    appreciated...also, here is the code I have so far below.

    you have a 4 enterframe loops running continually when they
    only need to run after a menu item has been clicked and can stop
    after all menu items have reached their final positions.
    and you need to compute the final positions for each menu
    item after one of them is clicked.
    you might do better to check for an as3 tutorial for an
    accordian menu. it's a bit more involved than you're thinking.

  • Loading AS2 mc's into AS3 movies

    Hi. Using the following code to import AS2 mcs into AS3.
    var contenedor = new Loader();
    contenedor.load(new URLRequest("animal_catch2.swf"));
    addChild(contenedor);
    contenedor.x = 100
    contenedor.y=0
    BUT doesn't work too well. Games don't work but and the image is displaced. Would appreciate any help.
    Thanks in advance.

    Sorry, excuse me. The displacement was becuase I cut and pasted the and I've just seen x = 100.
    Anyway, the game still doesn't work.
    Also, even if mcs are imprted and have different sizes than the container, can't they fill the container anyway - with fullscreen or something.

  • Dummy Guide needed for converting AS2 code into AS3

    I have to convert my existing AS2 code into AS3, but I might as well be reading chinese. I never even began to learn AS3, it was still fairly new at the time and the class ended before we had an opportunity to even touch on it. My major was not web design, it was the print side of design. I took an additional class, after I graduated, to learn web design and our teacher told us, basically, that we were designers, not coders so we won't be getting much into actionscripting, beyond the basics. At the time I was relieved, but looking back, I really wish we would have gotten more into it. Bottom line, I need to learn now.
    Is there ANYONE that can help me out? I will list my code below, buy I am way beyond lost any help that can be provided, I would be so grateful!!!!
    On the main timeline I have the basic..
    stop(); -- I found the AS3 version, but I don't know what I'm looking at. I get "not_yet_set.stop()" and there are are 8 options I can choose from. I just want the timeline to stop until I tell it where to go next. And what is "not_yet_set"
    Then I have my buttons, which are, basically...
    on (release) {
    gotoAndStop("Home");
    Or "gotoAndPlay("Whatever");"
    I also have buttons for scrolling...
    on (press) {
    play();
    on (release) {
    stop();
    AND
    on (press) {
    _root.AboutMe_Controller.gotoAndPlay(…
    on (release) {
    _root.AboutMe_Controller.gotoAndStop(…
    For the on(release) command, this is what I found as the AS3 version: not_set_yet.dispatchEvent()

    because that's really as1 code, you have steeper learning curve than going from as2 to as3.
    first, remove all code from objects, assign instance names to your buttons and you can then start on as3:
    // so, if you name your home button, home_btn:
    home_btn.addEventListener(MouseEvent.CLICK,homeF);
    function homeF(e:MouseEvent):void{
    gotoAndStop("Home");
    p.s.  the not_yet_set stuff is there because you tried to use script assist or some other actionscript shortcut.

  • Load AS2 swf into AS3 swf problem

    I have a flash with AS3 and inside this swf i load in a AS2 swf.
    to load swf works just fine, but the problem is when i load this i want to go to
    a specific part of it, for example i want to go to frame 3 in the loaded swf.
    i must control this from the AS3 swf, does someone know if this is possible?
    thanks in advance

    so can i do like this then to go to frame 3 in my loaded swf?
    MovieClip(ldr.content).gotoAndStop(3); ?
    sorry for being such an airhead
    thanks for helping me out =)
    Date: Sun, 7 Jun 2009 10:25:09 -0600
    From: [email protected]
    To: [email protected]
    Subject: load AS2 swf into AS3 swf problem
    no.
    if, in your loaded swf, you have a function f1() on the loaded swf's main timeline and you load that swf using a loader (say ldr), use:
    MovieClip(ldr.content).f1();   // to call f1() in the loaded swf
    >

  • Please help 'Translate' These codes from AS2 to AS3 for me

    Hi, i need help 'translating' these codes from Action Script 2 to Action Script 3. Please Do it for me:
    toc    loadText = new LoadVars();
        loadText.load("Curie.txt");
        loadText.onLoad = function(success) {
            if (success) {
                // trace(success);
                Curie.html = true;
                Curie.htmlText = this.Curie;
    Please translate it for me, i need it ASAP thanks
    Kenneth

    Thank you for helping me
    Kenneth
    Date: Thu, 15 Oct 2009 05:49:14 -0600
    From: [email protected]
    To: [email protected]
    Subject: Please help 'Translate' These codes from AS2 to AS3 for me
    Take a look at that:
    http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/migration.html
    There is a LoadVars section on that.
    There is also a tutorial here:
    http://www.republicofcode.com/tutorials/flash/as3externaltext/
    Cheers,
    CaioToOn!
    >

  • External as2 userDrawingTablet into as3

    created a tablet where the user could draw on the pad. i did it a while ago using actionscript 2. now i'm loading it externally into as3. when placed in as3 it seems to be confused as to where the tablet is and draws only on the bottom right and off the page. also have a text function that is not working properly either.
    kind of a random application and random problem, but not sure where else to go with this...
    was just wondering if anyone had done this and had a similar problem?
    thanx

    "submitter" is a movie clip on the main timeline. this code is inside submitter layed out with a mc named "blackboard". blackboard has a mc named "innerBlackboard" inside of it.
    blackboard.clearChalk = function():Void {
        var cl = this._parent._parent.chalkLine;
        this.createEmptyMovieClip("chalkLayer", 0);
        this.chalkLayer.lineStyle(cl.thickness, cl.color, cl.alpha);
        this.drawings = [];
    blackboard.clearText = function():Void {
        this.createEmptyMovieClip("textLayer", 10);
        this.textfields = [];
    blackboard.clearAll = function():Void {
        this.clearChalk();
        this.clearText();
    blackboard.enterDrawMode = function():Void {
        this.innerBlackboard.onPress = this.startDraw;
    blackboard.startDraw = function():Void {
        var x:Number = Math.round(this._xmouse);
        var y:Number = Math.round(this._ymouse);
        var coordinates = [x + "," + y];
        this._parent.currentDrawing = coordinates;
        this._parent.drawings.push(coordinates);
        this._parent.chalkLayer.moveTo(x, y);
        this._parent.onMouseMove = this._parent.drawChalk;
        this.onRelease = function() {
            delete this._parent.onMouseMove;
    blackboard.endDraw = function():Void {
        delete this.onMouseMove;
        delete this.innerBlackboard.onRelease;
    blackboard.drawChalk = function():Void {
        if (this.hitTest(_root._xmouse, _root._ymouse)) {
            var x:Number = Math.round(this._xmouse);
            var y:Number = Math.round(this._ymouse);
            this.currentDrawing.push(x + "," + y);
            this.chalkLayer.lineTo(x, y);
        } else {
            this.endDraw();
        updateAfterEvent();
    blackboard.enterTextMode = function():Void {
        this.innerBlackboard.onPress = this.startText;
    blackboard.startText = function():Void {
        var d:Number = this._parent.textLayer.getNextHighestDepth();
        var x:Number = this._parent._xmouse;
        var y:Number = this._parent._ymouse;
        this._parent.textLayer.createTextField("t" + d, d, x, y, this._parent.width - x, this._parent.height - y);
        var tf:TextField = this._parent.textLayer["t" + d];
        this._parent.textfields.push(tf);
        tf.type = "input";
        tf.multiline = true;
        tf.wordWrap = true;
        tf.restrict = "^'<>";
        tf.setNewTextFormat(this._parent._parent._parent.chalkFormat);
        tf.embedFonts = true;
        tf.text = "Type message";
        Selection.setFocus(tf);
        Selection.setSelection(0, tf.text.length);
        tf.onKillFocus = function() {
            this.type = "dynamic";
            this.selectable = false;
    blackboard.formatEntry = function():String {
        var tf:TextField;
        var d:Object;
        var entryXML    =  "<entry>";
        entryXML        +=         "<text>";
        for (var i:Number = 0; i < this.textfields.length; i++) {
            tf = this.textfields[i];
            entryXML    +=            "<field x='" + tf._x + "' y='" + tf._y + "' text='" + tf.text + "' />";
        entryXML        +=         "</text>";
        entryXML        +=         "<drawings>";
        for (i = 0; i < this.drawings.length; i++) {
            d = this.drawings[i];
            entryXML    +=            "<drawing coordinates='" + d.join("|") + "' />";
        entryXML        +=         "</drawings>";
        entryXML        += "</entry>";
        return escape(entryXML);
    blackboard.clearAll();
    blackboard.innerBlackboard.useHandCursor = false;
    blackboard.width = blackboard._width;
    blackboard.height = blackboard._height;
    draw_bn.onRelease = function() {
        blackboard.enterDrawMode();
        text_bn.gotoAndStop("_Up");
        text_bn.enabled = true;
        this.gotoAndStop("_Down");
        this.enabled = false;
    text_bn.onRelease = function() {
        blackboard.enterTextMode();
        draw_bn.gotoAndStop("_Up");
        draw_bn.enabled = true;
        this.gotoAndStop("_Down");
        this.enabled = false;
    clear_bn.onRelease = function() {
        blackboard.clearAll();
    submit_bn.onRelease = function() {
        var name:String = name_if.text;
        if (name == "" || name == "name (required)") return;
        var email:String = email_if.text;
        if (email == "" || email == "email (required)") return;
        entry = new LoadVars();
        entry.name = name;
        entry.email = email_if.text;
        entry.message = blackboard.formatEntry();
        returnEntry = new LoadVars();
        returnEntry.onLoad = traceReturn;
        entry.sendAndLoad("submitEntry.php", returnEntry);
    function traceReturn() {
        if (this.result == "success") {
            blackboard.clearAll();
    name_if.onSetFocus = email_if.onSetFocus = function() {
        this.text = "";
        delete this.onSetFocus;
    name_if.restrict = email_if.restrict = "^'<>";

  • Converting small amount of AS2 to AS3

    Hi All,
    I’m struggling to convert this block of AS2 code into AS3. It is a Netstream video component and I have made the scrubber able to be dragged anywhere inside the player. (Vertical and Horizontal). The scrubber is also coded so that it controls the frame position of the player (I have links that appear at certain points to load in other videos)
    Here is the as2 version; http://websites.danielnwilliams.co.uk/crankmedia/
    Im just trying to convert this as2 code to as3;
    MovieClip.prototype.scrubbb2 = function (x)
        var f2:Number = Math.round (this._totalframes * x);
        this.gotoAndStop (f2);
    var isPlaying2:Boolean = true;
    var scrubInterval2;
    function scrubit2() {
        ns2.seek(Math.floor((scrubmain.scrubbuttonmain._x/760) * duration2));
    scrubmain.scrubbuttonmain.onPress = function() {
        ns2.pause();
         if (isPlaying2) {
                 ns2.pause(true);
                  scrubmain.scrubbuttonmain.cog_pausemain._visible = true;
                scrubmain.scrubbuttonmain.cog_playmain._visible = false;
                trace("paused");
                  isPlaying2 = false;
       } else {
                  ns2.pause(false);
                 scrubmain.scrubbuttonmain.cog_pausemain._visible = false;
                scrubmain.scrubbuttonmain.cog_playmain._visible = true;
                trace("playing");
                 isPlaying2 = true;
        clearInterval(videoInterval2);
        scrubInterval2 = setInterval(scrubit2,10);
        this.startDrag(false,0,-392,760,0);
        this.onMouseMove = function()
            var x:Number = this._x;
            scrubbb2 (x / 760);
    scrubmain.scrubbuttonmain.onRelease = scrubmain.scrubbuttonmain.onReleaseOutside = function () {
        clearInterval(scrubInterval2);
        videoInterval2 = setInterval(videoStatus2,100);
            this.stopDrag();
    Finding this chunk really hard to to so, so would really appreciate it if someone could help me out!
    Much appreciated
    Dan

    It is unlikely that someone would be able/willing to attempt the full conversion. No only it is time consuming - there are some things in your AS2 version that are not straight forward.
    Here is a link that may help you:
    http://livedocs.adobe.com/flex/201/langref/index.html?migration.html&all-classes.html
    Also, read about MouseEvent for this is how you enable buttons functionality.

  • Changing Code Into AS3

    I have a code that I wrote in AS2 and I am now trying to
    convert it into AS3 . . . When I converted it this is what I came
    up with but I can still not get it to work.
    Can someone help me fix it? I used a coverter for some of it
    http://www.5etdemi.com/convert/index.php
    . . . does anyone know of a better one?
    Thanks for any help fixing the code

    :

  • AS2 with AS3 integration

    Hi.
    I have loads of games in AS2 but a freelancer is developping games in AS3. Can I use a container movie in AS3 and load both AS2 and AS3 games in. Otherwise I would have to update all games into AS3. Would all games have to be published to the same flashplayer? ie: FS7 etc...

    you can use an as3 swf to load as2 swfs.  if you need to communicate between the two swfs, use the localconnection class.

  • AS2 vs AS3

    Hi,
    I was just wondering in what format do people usually publish in: AS2 or AS3? Since there seems to be more widgets in AS2, do people actually publish in AS3?
    I'm investigating creating Widgets and I was planning to do it in AS3 but ... is it the right choice?
    What are you publishing in?
    Whyves

    Hi there
    While I agree with what Lilybiri is saying, I'll add my own thoughts here.
    Personally, I tend to use the defaults for many things with Captivate. And one of the defaults is that it defaults to AS2 setting. The only time I might consider using AS3 would be if someone were to offer something I needed to use that only was available in AS3. Then I would change. But I haven't encountered that situation so far.
    So sure, I'm keeping an eye to the future as far as AS3 goes, but it doesn't really factor into the things I do daily. AS2 setting is default and seems to work fine. There are some nuances between the two as far as Captivate goes that you might consider.
    For example, one of them is that if settings are AS2 and you are using variables in captions, you see a momentary flash of the variable before the value actually appears. I believe that goes away and is corrected if you switch to AS3.
    Additionally, I presently am awfully Flash and AS ignorant. So if I were to finally begin learning the mysteries of ActionScript, I might be a lot more concerned.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • AS1/AS2 to AS3 onClipEvent(load),onClipEvent(enterFrame)

    onClipEvent (load) {
         total = _root.getBytesTotal();
    onClipEvent (enterFrame) {
         loaded = _root.getBytesLoaded();
         percent = int(loaded/total*100);
         text = percent+"%";
         gotoAndStop(percent);
         if (loaded == total) {
              _root.gotoAndPlay(2);
    Dear all,
    I found a sample code that is writen in AS1/AS2 to see if the load is finished, If finish loading, it will go to the next frame. How do I convent this into AS3? This is my first time looking at AS1/AS2 code, especially onClipEvent (load), _root.getBytesTotal(), onClipEvent (enterFrame), _root.getBytesLoaded(),_root.gotoAndPlay(2).
    Can someone help me out with this?
    Thanks,
    -Zainuu

    Hi, Thanks for the reply
    stop();
    this.addEventListener(Event.ENTER_FRAME, loading);
    function loading(e:Event):void{
        var total:Number = this.stage.loaderInfo.bytesTotal;
        var loaded:Number = this.stage.loaderInfo.bytesLoaded;
         trace(total);
         trace(loaded);
        if (total == loaded){
            play();
            mc_Loader.visible=false;
            this.removeEventListener(Event.ENTER_FRAME, loading);
    I tried to trace the total bytes and loaded bytes, it returns me
    total = 405668
    loaded = 405668
    Is there a way to show the loaded bytes starting from 1 till 405668? I'm trying to find out if it is really loading the thing. Otherwise is there any other ways to slow down the loading for a bit because it only shows my loading bar for 0.5secs, not really sure if its really loading it...

  • ActionScript Newbie: Learn AS2 or AS3?

    I'm wanting to get into Flash development, and I'm trying to
    work out which language to learn. Do I take this opportunity to
    skip straight to the newer ActionScript 3? Or do I learn the
    "simpler" AS2, and migrate once I've mastered it?
    I'm hoping to use my development skills mainly for animation
    (not fully blown Flex apps).
    Any help appreciated. Thanks very much.

    There is definitely a much much higher learning curve for AS3
    and learning
    resources (as mentioned) are limited. You may want to
    consider your own
    skills as a programmer before deciding to jump into AS3.
    Starting small
    with AS1 or even AS2 basics might be easier until you get
    familiar enough
    with AS to get into AS3 (which is still fairly new and not
    yet widely used).
    "David Stiller" <[email protected]> wrote in
    message
    news:[email protected]...
    > mambo_06,
    >
    >> Excellent, thanks. I'll probably invest in a copy of
    Flash
    >> CS3 (I've got version 8 at the moment).
    >> Any recommendations on books for learning
    ActionScript
    >> 3.0, then?
    >
    > The only tough part about making recommendations at this
    point (May,
    > 2007) is that many of the ActionScript 3.0 books are
    still being written.
    > I should clarify that: they're still being written
    specific to Flash (as
    > opposed to Flex). Flex Builder was the first official
    IDE to support AS3,
    > so you'll find Flex books out there, but those may end
    up frustrating you
    > if you're more a Flash dev at heart.
    >
    > I recommended the Moock book to Rothrock specifically
    because we've
    > been friends (Rothrock and I) for some time, and I
    imagine it will be well
    > suited to his comfort level with ActionScript. Moock is
    a gifted
    > communicator, able to explain programming concepts
    clearly. Even so, his
    > books tend to appeal more to intermediate/advanced
    readers, as Rothrock
    > suggested.
    >
    > The Peters book is great for -- as the title implies --
    making things
    > move. It's an animation-via-programming book, and
    belongs within an arm's
    > reach of anyone interested in game development or
    programmatic visual art.
    >
    > For an all-purpose approach to object-oriented
    programming in general,
    > I've been recommending Object-Oriented Programming for
    Flash 8, by Peter
    > Elst and Todd Yard, for a while now. Of course, that
    relates only to
    > ActionScript 2.0. I really don't know if they have a
    second edition in
    > the works, but if so, I would probably recommend it
    without even reading
    > it, as Elst and Yard are top notch developers, and their
    first edition is
    > great.
    >
    > There's a forthcoming Foundation ActionScript 3.0 with
    Flash CS3 and
    > Flex 2, by Steve Webster and Sean McSharry (should be
    ready in June).
    > I've read a handful of early-draft chapters and can say
    it looks
    > promising. That one is geared toward newcomers.
    >
    >
    > David Stiller
    > Adobe Community Expert
    > Dev blog,
    http://www.quip.net/blog/
    > "Luck is the residue of good design."
    >

Maybe you are looking for

  • Custom Ringtones Show Up in iTunes Folder, but Not on iPhone

    I've recently upgraded from a 3GS to a 4G. I have a few custom ringtones that I created from .MP3 files (converted to .m4r files). I had these same ringtones installed on my 3GS and want them on my 4G. I transferred to my 4G by dragging them from the

  • Dvd burning and ripping

    Dose anyone know where one could find a dvd copying program like the windows based dvd decripter, and dvd shrink. it would be great if anyone knows of any.

  • HT1178 time_capsule password

    How do I find the Time_Capsule Password?

  • Regarding dynamic selection

    hi , this is rekha, i having the two  fields like one parameter one select-option(date range that is date from ,date to ) its an relation between ui screen and abap . UI screen having  fields like parameter and select-option and iam writting the code

  • Deleting Mac Combo Update 10.2.8?

    I upgraded my Clamshell yesterday to 10.3 with disks from AppleRescue. I also put it an Airport card, realizing I'll need to d'load the 10.3.9 update to have full use of Panther; having dial-up makes these large d'loads impossible. My question is whe