Problem translating AS2 code

Hi
I'd appreciate it if anyone can help me with this.
I have a basic menu that I created in AS2, this can be seen
here:
http://www.qwerty-design.co.uk/example2.html
I have the menu working in AS3 but I just can't get the
buttons to stay down like they do in this example. My scripting
knowledge is limited and I need to get this sorted by Monday.
Please help.
if it would help I can post the AS2 code.
My code so far

Tried the code and I think we are nearly there, but there are
two small problems,
1. I need one the first button to be down at the start
2. When I click one of the buttons an error is thrown up as
follows
TypeError: Error #1009: Cannot access a property or method of
a null object reference.
at Test_fla::MainTimeline/onButtonClicked()
The code now looks like this:

Similar Messages

  • Translate AS2 code to AS3

    sliceArray=["slice1","slice2","slice3","slice4","slice5","slice6","slice7",
    "slice8","slice9","slice10"];
    function rotateMC(num:Number)
        for (i=0;i<= sliceArray.length;i++)
                var myName=eval(sliceArray[i]);
                myName._rotation+=num;
    btn1.onPress=function(){
    this.onEnterFrame=function(){
        rotateMC(10);
    btn1.onRelease=function(){
    delete this.onEnterFrame;
    btn2.onPress=function(){
    this.onEnterFrame=function(){
        rotateMC(-10);
    btn2.onRelease=function(){
    delete this.onEnterFrame;

    the generic answer to your generic question would be to learn AS3. Do you have a specific question?
    What have you tried on your own? Are you stuck on a specific part?
    I don't think you can use eval anymore (and it has been a bad idea since Flash 6 anyways) so for that you can use the array notation:
    someParentObject["childname"+variable]
    And all the various different ways of handling events have been replaced with:
    someObject.addEventListener("theEvent",handlerFunction)
    function handlerFunction(e:Event):void{
    // code here

  • 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!
    >

  • Noob question: How to update very basic as2 code to as3.

    I've been asked to update a web banner with old as2 code, and not being a coder or a regular Flash user, I'm stuck with what I'm sure is a simple problem. The code in the opening frame is;
    function timeOut(pauseTime) {
      stop();
      pauseTimer = setInterval(this, "goPlay", pauseTime);
    function goPlay() {
      play();
      clearInterval(pauseTimer);
    After that there are a few frames that include timeOut(500); code, which seems basic enough, so I imagine my problems are all in the opening code.
    I get 4 errors that all refer to Frame 1;
    1120: Access of undefined property pauseTimer.
    1067: Implicit coercion of a value of type CapOne_MM_648x480b_fla:MainTimeline to an unrelated type Function.
    1067: Implicit coercion of a value of type String to an unrelated type Number.
    1120: Access of undefined property pauseTimer.
    Can anyone help or point me in the right direction? Thanks.

    For the code you show there would be no need to convert to AS3 since between AS2 and AS3 it hasn't changed.  One thing you do need to do is declare variables and since pauseTimer is used in mutliple functions it needs to be declared outside any functions.  Another thing you need to do is specify the variable types, including the arguments passed into function.  As for the setInterval call itself it appears to be written incorrectly....
    var   pauseTimer:Number;
    function timeOut(pauseTime:Number) {
          stop();
         pauseTimer = setInterval(goPlay, pauseTime);

  • Change as2 code to as3

    I used a tutorial http://www.flash-game-design.com/flash-tutorials/funky-flash-website-tutorial-5.html to make a menu for my application, I've tried following tips on how to change AS2 code to AS3, but it just doesn't work.
    menu = ["bulls", "about", "roster", "schedule"];
    var current = menu[0];
    for (var i = 0; i<menu.length; i++) {
    var b = menu[i];
    this[b+"_btn"].stars._visible = false;
    this[b+"_btn"].txt = b;
    this[b+"_btn"].onPress = function() {
    _root.site[current+"_btn"].stars._visible = false;
    _root.site[this.txt+"_btn"].stars._visible = true;
    current = this.txt;
    _root.site.content.gotoAndStop(this.txt)
    this[current+"btn"].stars._visible = true;
    this.onEnterFrame = function() {
    this[current+"_btn"].stars.s1._rotation += 1;
    this[current+"_btn"].stars.s2._rotation += 0.5;
    Thank you,
    Glenn

    Just a note. Function declarations in a loop is an EXTREMELY bad practice that will lead to many problems if it doesn't have some already. So, the following lines:
    for (var i:int = 0; i<menu.length; i++) {
        var b:String = menu[i];
        this[b+"_btn"].stars.visible = false;
        this[b+"_btn"].addEventListener(MouseEvent.CLICK,fn);
        this[b+"_btn"].txt=b;
        function fn(e:MouseEvent):void{
            this[current].stars.visible = false;
            var nam:String=e.target.parent.name;
            this[nam].stars.visible = true;
            current = nam;
            //MovieClip(root).site.content.gotoAndStop(this.txt)
    should be:
    for (var i:int = 0; i < menu.length; i++) {
         var b:String = menu[i];
         this[b+"_btn"].stars.visible = false;
         this[b+"_btn"].addEventListener(MouseEvent.CLICK,fn);
         this[b+"_btn"].txt=b;
    function fn(e:MouseEvent):void {
         this[current].stars.visible = false;
         var nam:String=e.target.parent.name;
         this[nam].stars.visible = true;
         current = nam;
         //MovieClip(root).site.content.gotoAndStop(this.txt)

  • What are changes between FP 10.0.42.34 and 10.0.45.2 that could cause AS2 code to run differently?

    Hi, I am trying to debug a large Flash reading literacy application which is written in AS2. Everything works in 10.0.42.34. When our school customers upgrade to 10.0.45.2 they get blocked from proceeding with training.
    The main movie has loaded an application to run a sequence of tutorial movieclips, driven by an xml input.
    The application waits for each background plus movie to load and the plays the movie.
    It then unloads the movie and background and proceeds to the next movie/background.
    I am running the debugger in CS4 in both FP 10.42.34 and FP 10.0.45.2, the two [UnloadSWF] trace outputs happens in both, but the next step is missed. I am delving into the code right now, but I hope that there may be a hint in the changes made.
    I see no errors or security sandbox issues in the trace output.
    Can someone tell me what main changes there are in FP 10.0.45.2 that could cause AS2 code to run differently?
    Currently we are going to tell our customers that they must downgrade Flash Player to keep their kids learning to read.
    Thanks,
    Sue W.

    All these bug reports are probably describing same problem:
    http://bugs.adobe.com/jira/browse/FP-3993
    http://bugs.adobe.com/jira/browse/FP-4137
    http://bugs.adobe.com/jira/browse/FP-4121
    Not yet any word from Adobe that this is considered a bug worth fixing.
    I would also like to add that the bug failing to load or run older AS1/2 swfs is present in both latest release version FP 10.0.45.2 and FP 10.1.51.95 (beta 3). So it does not look like it has been fixed with 10.1

  • Trying to find out which line of AS2 code is causing flash player crash in firefox & chrome browser

    Hello,
    I have a flash movie (AS2) created for the website visitors' registration and this flash movie is longer in size than the browser's window height so that site visitors need to browse down using browser's vertical scroll bar to see all of the contents in the flash movie.
    When users click the submit button in the flash movie then
    Firstly, the AS2 code attached to the      on(release){    event scrolls the html page back to the top (because the user must have scrolled down to view the flash movie content at the bottom of the page and I want the html page to go back to the top of the page)
    getURL("javascript:window.scroll(0,0)");    // this is the AS2 code I have used for scrolling the page back to the top. I suspect this code is causing the flash player crash in firefox and google chrome
    and also tells the _root of the flash movie to go to and stop at a frame named "StartEnteringData".
    _root.gotoAndStop("StartEnteringData")     //making the _root of the movie to go to the "StartEnteringData" frame
    this.gotoAndStop("Start")                                  //making this movieclip which contains the registation form to go to the first blank frame labelled "Start"
    The "StartEnteringData" frame on the _root of the flash movie has AS2 code for entering the registration data to the database by using loadVariablesNum( ... )
    Here's my question.
    Almost everytime the user/visitor click the Submit button, the firefox browser users and google chrome browswer users see the Flash Player CRASH...
    This doesn't happen often with the website visitors using MS Internet Explorer.
    I have read some www articles (by searching google) saying that Adobe Flash Player in Firefox and Chrome browsers crash a lot.
    But, for my flash movie, everytime the visitor clicks the submit button, flash player crashes. Therefore, I guess it is the AS2 code that I'm using (associated with the on(release) event of the submit button) is causing the flash player crash rather then the flash player compatibility with Firefox and Chrome browsers.
    So, someone please tell me what's causing the flash player crash.
    Is there a better code to make a web page to go back to the top?
    I am also using the codes shown below on the first keyframe of the main movie. (_root)
    //For custom flash right click menu:
    var myMenu_cm:ContextMenu = new ContextMenu();
    myMenu_cm.builtInItems.zoom = true;
    myMenu_cm.builtInItems.quality = false;
    myMenu_cm.builtInItems.print = false;
    myMenu_cm.builtInItems.save = false;
    myMenu_cm.builtInItems.loop = false;
    myMenu_cm.builtInItems.rewind = false;
    myMenu_cm.builtInItems.play = false;
    myMenu_cm.builtInItems.forward_back = false;
    _root.menu = myMenu_cm;
    //For tiling the flash movie background with bitmap picture
    import flash.display.BitmapData;
    var tile:BitmapData = BitmapData.loadBitmap("pattern");
    this.beginBitmapFill(tile);
    this.lineTo(Stage.width, 0);
    this.lineTo(Stage.width, Stage.height);
    this.lineTo(0, Stage.height);
    this.lineTo(0, 0);
    this.endFill();

    by repeatedly commenting out lines of code you suspect are causing the crush and retesting you should be able to pinpoint the problem.

  • Problem with php code. Please help!

    Hello!
    I'm using the following syntax to bring content into my
    websites' layout template:
    Code:
    <?php //check in the root folder first
    if(file_exists('./' . $pagename . '.php'))
    include './' . $pagename . '.php';
    //if it wasn't found in the root folder then check in the
    news folder
    elseif(file_exisits('./news/' . $filename . '.php'))
    include './news/' . $pagename . '.php';
    // if it couldn't be found display message
    else
    echo $pagename . '.php could not be found in either the root
    folder or the news folder!';
    } ?>
    What it's essentially saying is, if you can't find the .php
    file in the _root folder, look for it in the /news/ folder.
    It works perfectly if loading something from the _root folder
    but I get an error if I need to bring something from the /news/
    folder.
    Can anyone see any potential problems with my code?
    Thank you very much and I hope to hear from you.
    Take care,
    Mark

    I've never seen the code written like that before, but I'm
    assuming it's
    legal?
    Perhaps try:
    <?php
    $newsroot = $_SERVER['DOCUMENT_ROOT']."/news";
    if (!file_exists("$pagename.php")) {
    elseif (!file_exists("$newsroot/$pagename.php")) {
    else
    Or the other thing you can try is replacing the elseif
    statement with:
    elseif (!file_exists("news/$pagename.php"))
    If not - I'm sure Gary will be on here soon...
    Shane H
    [email protected]
    http://www.avenuedesigners.com
    =============================================
    Proud GAWDS Member
    http://www.gawds.org/showmember.php?memberid=1495
    Delivering accessible websites to all ...
    =============================================
    "Spindrift" <[email protected]> wrote in
    message
    news:e5mled$272$[email protected]..
    > Hello!
    >
    > I'm using the following syntax to bring content into my
    websites' layout
    > template:
    >
    > Code:
    >
    > <?php //check in the root folder first
    > if(file_exists('./' . $pagename . '.php'))
    > {
    > include './' . $pagename . '.php';
    > }
    > //if it wasn't found in the root folder then check in
    the news folder
    > elseif(file_exisits('./news/' . $filename . '.php'))
    > {
    > include './news/' . $pagename . '.php';
    > }
    > // if it couldn't be found display message
    > else
    > {
    > echo $pagename . '.php could not be found in either the
    root folder or
    > the
    > news folder!';
    > } ?>
    >
    > What it's essentially saying is, if you can't find the
    .php file in the
    > _root
    > folder, look for it in the /news/ folder.
    >
    > It works perfectly if loading something from the _root
    folder but I get an
    > error if I need to bring something from the /news/
    folder.
    >
    > Can anyone see any potential problems with my code?
    >
    > Thank you very much and I hope to hear from you.
    >
    > Take care,
    >
    > Mark
    >

  • 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.

  • Help! Convert simple Flash AS2 code to AS3

    Hi everyone,
    I'm a Flash beginner and followed a tutorial: http://www.webwasp.co.uk/tutorials/018/tutorial.php ... to learn how to make a "live paint/draw" effect. I didn't realize  that if I made something in AS2, I wouldn't be able to embed it (and  have it work) into my root AS3 file, where I've got a bunch of other  stuff going on. I've tried following tips on how to change AS2 code to  AS3, but it just doesn't work. I know it's simple code, and that some  genius out there can figure it out, but I'm at a loss. Please help!
    Here's the AS2 code:
    _root.createEmptyMovieClip("myLine", 0);
    _root.onMouseDown = function() {
       myLine.moveTo(_xmouse, _ymouse);
       ranWidth = Math.round((Math.random() * 10)+2);
       myLine.lineStyle(ranWidth, 0xff0000, 100);
       _root.onMouseMove = function() {
          myLine.lineTo(_xmouse, _ymouse);
    _root.onMouseUp = function() {
       _root.onMouseMove = noLine;
    Thanks in advance!
    Signed,
    Nicolle
    Flash Desperado

    Considering the code is on timeline:
    var myLine:Sprite = new Sprite();
    addChild(myLine);
    var g:Graphics = myLine.graphics;
    addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    function onMouseDown(e:MouseEvent):void {
         var ranWidth:Number = Math.round((Math.random() * 10) + 2);
         g.clear();
         g.lineStyle(ranWidth, 0xFF0000, 1);
         addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
         addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    function onMouseMove(e:MouseEvent):void {
         g.lineTo(mouseX, mouseY);
    function onMouseUp(e:MouseEvent):void {
         removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
         removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);

  • Help plsss converting this AS2 code to AS3!!

    here is a little AS2 code that is in fact a photo gallery
    that i use in my site and i want to convert it to AS3 but i just
    cant seem to get it right... could someone plssss help me?!?!

    with what part are you having trouble?

  • Need assistance converting some AS2 code to AS3

    Hi,
    I have some simple AS2 code that brings in a MovieClip when
    you click a button. This is currently AS2, and I would rather
    convert it to AS3. I also have some code which closes the MovieClip
    upon button Click.
    The code I am currently using is below:

    addMC is the name of one of the event handler functions, not
    the button(s). the button instance names are: addButton and
    removeButton.
    To have three of them, duplicate what you see and have new
    variables, functions, and button names for all three sets, adjusted
    appropriately.
    I'm pretty sure this isn't over yet, I'm just giving you code
    per your defined scenario, which may have a hole or two in it. Try
    it out and see what you really want to do, then come back when you
    find out things need to be tamed in some way or aren't working as
    you want. There are more complicated ways to deal with a situation
    depending on what you really want, and I'm one who prefers to see
    some work done at your end that shows you've tried something (I'm
    not mean, much, I just have this thing about learning by doing).

  • Has anyone one else had problems redeeming the code for the free onetime download of Star Trek 2009 Movie?

    Has anyone one else had problems redeeming the code for the free onetime download of the Star Trek 2009 Movie?

    dawnfromcabot wrote:
    ITUNES HAS CHARGED MY DEBIT CARD $99.99 FOR GLOBAL WAR RIOT-SOME GAME I DID NOT KNOW WAS LOADED ON MY OTHER PHONE; HOWEVER, WHEN I PULLED UP THIS APP TO SEE EXACTLY WHAT IT WAS WAS I SURPRISED TO SEE I COULD DOWNLOAD IT FOR 'FREE'. I HAVE CONTACTED ITUNES THROUGH THIS REDICULOUSLY CHICKEN SH_T SYSTEM THEY USE SO THEY DO NOT ACTUALLY HAVE TO HEAR HOW UPSET A PERSON IS NOW THAT THEY CANNOT BUY FOOD FOR THEIR CHILDREN BECAUSE OF A MISTAKE MADE ON ITUNES PART.  I DID RECEIVE AN EMAILED RESPONSE FROM STEPHANIE WHO ADVISED THIS WAS PUCHARED ON A PHONE THAT HAS PURCHASED DOWNLOADS IN THE PAST. I WONDER IF SHE THOUGHT TO LOOK AT MY ENTIRE DOWNLOAD HISTORY AND DISCOVER THAT NOTHING HAS EVER BEEN PURCHASED ON MY ITUNE ACCOUNT IN THE AMOUNT REMOTELY CLOSE TO WHAT THEY ARE CHARGING ME NOW.  THAT IS BECAUSE I DO TRY TO MONITOR THIS ACCOUNT AND OBVIOUSLY THIS LAST PURCHASE WAS DONE WITHOUT MY KNOWLEDGE UNTIL I CHECKED MY ONLINE BANKING ACCOUNT, WHICH I DO EVERY DAY.  TO MAKE MATTERS WORSE THE APP STATES IT IS FREE TO INSTALL WHEN YOU PULL IT UP SO NO ONE HAS CLARIFIED TO MY WHERE THE $99.99 COMES INTO PLAY.  I WILL NOT DROP THIS UNTIL MY BACK ACCOUNT HAS BEEN PROPERERLY CREDITED IN THE SAME TIME FRAME IT TOOK YOU TO TAKE MY MONEY. I WILL LAUNCH A COMPLAINT WITH EVERY POSSIBLE ENTITY IN THE ITUNES COMPANY AND BUSINESSES OUTSIDE THAT REGULATE THEIR BUSINESS UNTIL THIS HAS RESOLVED IN MY FAVOR AS I AM THE ONE WHO HAS BEEN VICTIMIZED BY A COMPANY I INVITED INTO MY TELEPHONE NETWORK IN GOOD FAITH!!!!!!!!!!!!
    Reading that is giving me a headache, how about normal type.

  • What's the problem in this code

    import java.lang.reflect.*;
    import java.awt.*;
    class ABC
         public Integer i;
         ABC()
         public void setInt(Integer t)
              i = t;
    public class SampleName {
    public static void main(String[] args)
    ABC g1 = new ABC();
    g1.setInt(new Integer(10));
    printFieldNames(g1);
    static void printFieldNames(Object o) {
    Class c = o.getClass();
    Field[] publicFields = c.getDeclaredFields();
    for (int i = 0; i < publicFields.length; i++)
    try {
    Object ref = publicFields.get(c);
    System.out.println(" ref.toString() : " + ref.toString());
         }catch(Exception e)
                   e.printStackTrace();
    What is the problem with this code,at run time Iam getting this exception
    java.lang.IllegalArgumentException: object is not an instance of declaring class
    How can we get the value of field of an object

    Now it got this exception
    java.lang.IllegalAccessException
    at java.lang.reflect.Field.get(Native Method)That's strange - I didn't! ;-)
    Are you running exactly the same code as the code you posted (except for the one line I said to change)?

  • Please tell me what is the problem with this code

    Hai,
    Iam new to Swings. can any one tell what is the problem with this code. I cant see those controls on the frame. please give me the suggestions.
    I got the frame ,but the controls are not.
    this is the code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ex2 extends JFrame
    JButton b1;
    JLabel l1,l2;
    JPanel p1,p2;
    JTextField tf1;
    JPasswordField tf2;
    public ex2()
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setTitle("Another example");
    setSize(500,500);
    setVisible(true);
    b1=new JButton(" ok ");
    p1=new JPanel();
    p1.setLayout(new GridLayout(2,2));
    p2=new JPanel();
    p2.setLayout(new BorderLayout());
    l1=new JLabel("Name :");
    l2=new JLabel("Password:");
    tf1=new JTextField(15);
    tf2=new JPasswordField(15);
    Container con=getContentPane();
    con.add(p1);
    con.add(p2);
    public static void createAndShowGUI()
    ex2.setDefaultLookAndFeelDecorated(true);
    public static void main(String ar[])
    createAndShowGUI();
    new ex2();
    }

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ex2 extends JFrame
        JButton b1;
        JLabel l1,l2;
        JPanel p1,p2;
        JTextField tf1;
        JPasswordField tf2;
        public ex2()
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setTitle("Another example");
            b1=new JButton(" ok ");
            p1=new JPanel();
            p1.add(b1);
            p2=new JPanel();
            p2.setLayout(new GridLayout(2,2));
            l1=new JLabel("Name :");
            l2=new JLabel("Password:");
            tf1=new JTextField(15);
            tf2=new JPasswordField(15);
            p2.add(l1);
            p2.add(tf1);
            p2.add(l2);
            p2.add(tf2);
            Container con=getContentPane();
            con.add(p1, BorderLayout.NORTH);
            con.add(p2, BorderLayout.CENTER);
            pack();
            setVisible(true);
        public static void createAndShowGUI()
            ex2.setDefaultLookAndFeelDecorated(true);
        public static void main(String ar[])
            createAndShowGUI();
            new ex2();
    }

Maybe you are looking for