Is this the best way to write this in AS3

I have converted my old AS2 to As3. It now appears to work the same as before but being new to AS3 I have a few questions.
In this example I click on a button which takes me to a keyframe that plays a MC. There is another btn that takes me back to the original page.
In AS2 it is written like this.
// Go to keyFrame btn
on (release) {
//Movieclip GotoAndStop Behavior
this.gotoAndStop("Jpn_Scul_mc");
//End Behavior
// Play Movie
on (release) {
//Movieclip GotoAndStop Behavior
this.gotoAndStop("Jpn_Movie");
//End Behavior
//load Movie Behavior
if(this.mcContentHolder == Number(this.mcContentHolder)){
loadMovieNum("PL_Japan_Scul.swf",this.mcContentHolder);
} else {
this.mcContentHolder.loadMovie("PL_Japan_Scul.swf");
//End Behavior
// Return key
on (release) {
//Movieclip GotoAndStop Behavior
this.gotoAndStop("Jpn_Intro");
//End Behavior
In AS3 it is written like this.
// Play Movie
var myrequest_Jpn:URLRequest=new URLRequest("PL_Japan_Scul.swf");
var myloader_Jpn:Loader=new Loader();
myloader_Jpn.load(myrequest_Jpn);
function movieLoaded_Jpn(myevent_Jpn:Event):void {
stage.addChild(myloader_Jpn);
var mycontent:MovieClip=myevent_Jpn.target.content;
mycontent.x=20;
mycontent.y=20;
//unload method - Return to keyframe
function Rtn_Jpn_Intro_(e:Event):void {
gotoAndStop("Japan_Intro");
Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
function removeMovie_Jpn(myevent_Jpn:MouseEvent):void {
myloader_Jpn.unload();
myloader_Jpn.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_Jpn);
Rtn_Jpn_Intro_btn.addEventListener("click",Rtn_Jpn_Intro_);
// Go to keyFrame btn
function Scul_Play(e:Event):void {
gotoAndStop("Jpn_Scul_mc");
Jpn_Scul_btn.addEventListener("click",Scul_Play);
1. Is there a better, more efficient way to achieve this in AS3?
2. I have used an //unload method in the AS3 script which does remove the MC from the scene but I notice in the output tab my variable code is still being counted for the last MC played.
Is this normal?

Hi Andrei, I have started a new project and taken your advice to construct it with a different architecture with all the code in one place.
I have two questions regarding your last code update.
var myrequest_Jpn:URLRequest;
var myloader_Jpn:Loader;
Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
Jpn_Scul_btn.addEventListener(MouseEvent.CLICK, Scul_Play);
function Scul_Play(e:MouseEvent):void {
     myrequest_Jpn = new URLRequest("PL_Japan_Scul.swf");
     myloader_Jpn = new Loader();
     myloader_Jpn.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_Jpn);
     myloader_Jpn.load(myrequest_Jpn);
function movieLoaded_Jpn(e:Event):void {
     // remove listener
     myevent_Jpn.target.removeEventListener(Event.COMPLETE, movieLoaded_Jpn);
     this.addChild(myloader_Jpn);
     myloader_Jpn.x = 20;
     myloader_Jpn.y = 20;
     // remove objects that are in "Japan_Intro" frame
function removeMovie_Jpn(e:MouseEvent):void {
     // add back objects that are in "Japan_Intro" frame
     // remove from display list
     this.removeChild(myloader_Jpn);
     myloader_Jpn.unload();
     myloader_Jpn = null;
     // this moved from Rtn_Jpn_Intro_ function
     //gotoAndStop("Japan_Intro");
Its all works great except for the line to remove event..
1.
myevent_Jpn.target.removeEventListener(Event.COMPLETE, movieLoaded_Jpn);
I get an error:   1120: Access of undefined property myevent_Jpn.
Removing this statement allows the code to work but that is not a solution.
2.
Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
I would like this button to remove more than one movie. Is this possible.
Thanks for the help todate.

Similar Messages

  • What is the best way to write 10 channels of data each sampled at 4kHz to file?

    Hi everyone,
    I have developed a vi with about 8 AI channels and 2 AO channels... The vi uses a number of parallel while loops to acquire, process, and display continous data.. All data are read at 400 points per loop interation and all synchronously sampled at 4kHz...
    My questions is: Which is the best way of writing the data to file? The "Write Measurement To File.vi" or low-level "open/create file" and "close file" functions? From my understanding there are limitations with both approaches, which I have outlines below..
    The "Write Measurement To File.vi" is simple to use and closes the file after each interation so if the program crashes not all data would necessary be lost; however, the fact it closes and opens the file after each iteration consumes the processor and takes time... This may cause lags or data to be lost, which I absolutely do not want..
    The low-level "open/create file" and "close file" functions involves a bit more coding, but does not require the file to be closed/opened after each iteration; so processor consumption is reduced and associated lag due to continuous open/close operations will not occur.. However, if the program crashes while data is being acquired ALL data in the buffer yet to be written will be lost... This is risky to me...
    Does anyone have any comments or suggestions about which way I should go?... At the end of the day, I want to be able to start/stop the write to file process within a running while loop... To do this can the opn/create file and close file functions even be used (as they will need to be inside a while loop)?
    I think I am ok with the coding... Just the some help to clarify which direction I should go and the pros and cons for each...
    Regards,
    Jack
    Attachments:
    TMS [PXI] FINAL DONE.vi ‏338 KB

    One thing you have not mentioned is how you are consuming the data after you save it.  Your solution should be compatible with whatever software you are using at both ends.
    Your data rate (40kS/s) is relatively slow.  You can achieve it using just about any format from ASCII, to raw binary and TDMS, provided you keep your file open and close operations out of the write loop.  I would recommend a producer/consumer architecture to decouple the data collection from the data writing.  This may not be necessary at the low rates you are using, but it is good practice and would enable you to scale to hardware limited speeds.
    TDMS was designed for logging and is a safe format (<fullDisclosure> I am a National Instruments employee </fullDisclosure> ).  If you are worried about power failures, you should flush it after every write operation, since TDMS can buffer data and write it in larger chunks to give better performance and smaller file sizes.  This will make it slower, but should not be an issue at your write speeds.  Make sure you read up on the use of TDMS and how and when it buffers data so you can make sure your implementation does what you would like it to do.
    If you have further questions, let us know.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • What's the best way to write freehand with InDesign?

    I have a Wacom and want to place some handwriting on my document - what's the best way to do this?

    Try the pen or pencil tools or do it in Photoshop and place it.
    Bob

  • What is the best way to write management pack modules?

    i have written many modules using powershell script but when i deploy that management pack on SCOM it is throwing so many errors saying powershell script has dropped due to timeout.
    My Mp has lot of powershell script which gets the data from the service which executes for each and every instance the mp certainly has around 265 Instances and the powershell have to execute for each and every instance.
    how can i improve the scripts?
    do i need to use someother scripting language like javascript or VBScript in the management pack to execute different modules.
    what is the best practice to write Modules
    i have useed even the cookdown for multi instance data gathering
    Thanks & Regards, Suresh Gaddam

    One thing you have not mentioned is how you are consuming the data after you save it.  Your solution should be compatible with whatever software you are using at both ends.
    Your data rate (40kS/s) is relatively slow.  You can achieve it using just about any format from ASCII, to raw binary and TDMS, provided you keep your file open and close operations out of the write loop.  I would recommend a producer/consumer architecture to decouple the data collection from the data writing.  This may not be necessary at the low rates you are using, but it is good practice and would enable you to scale to hardware limited speeds.
    TDMS was designed for logging and is a safe format (<fullDisclosure> I am a National Instruments employee </fullDisclosure> ).  If you are worried about power failures, you should flush it after every write operation, since TDMS can buffer data and write it in larger chunks to give better performance and smaller file sizes.  This will make it slower, but should not be an issue at your write speeds.  Make sure you read up on the use of TDMS and how and when it buffers data so you can make sure your implementation does what you would like it to do.
    If you have further questions, let us know.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • What is the best way to write a math book?

    should i use graphic tablets such as wacom,smartpen etc. or should i type it using a program like math type.
    thanks for replies.

    should i type it using a program like math type.
    Yes.
    http://m10lmac.blogspot.com/2008/12/typing-equations-and-formulas.html
    But for serious math publications I think LaTeX is often used.

  • What is the best way to migrate duplicateMovieClip to AS3?

    Hi,
    In our project, we have seperate controller file for all the
    code and seperate for graphical assets. I mean, they both generate
    seperate swf files. Controller actually load the graphical assetts
    by Loader. I am still using Flash9 preview, as it will take a
    couple of days to get licences for CS3.
    The problem is, I have a movie clip inside the graphical
    assetts file, and it used to duplicate just fine in flash 9. Now I
    also gave it a a class name ItemMC and exported for action script.
    But it is giving me this error.
    ReferenceError: Error #1065: Variable ItemMC is not defined.
    while doing this
    var item_mc:MovieClip = new ItemMC();
    I also tried using getQualifiedClassName and
    getDefinitionByName using the existing instance of ItemMC, but it
    didn't work either. It was returning the right class name of ItemMC
    but it is still not instantiable. Any suggestions?

    >> Now I also gave it a a class name
    ItemMC and exported for action script. But it is giving me
    this error.
    ReferenceError: Error #1065: Variable ItemMC is not defined.
    while doing this
    var item_mc:MovieClip = new ItemMC();
    <<
    When you give a MC a class name in the linkage properties you
    are not making
    that MC a class that you can instance using new. That is for
    defining a
    custom class that you wrote which can extend the MovieClip
    class.
    Dave -
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Best way to write SELECT statement

    Hi,
    I am selecting fields from one table, and need to use two fields on that table to look up additional fields in two other tables.
    I do not want to use a VIEW to do this. 
    I need to keep all records in the original selection, yet I've been told that it's not good practice to use LEFT OUTER joins.  What I really need to do is multiple LEFT OUTER joins.
    What is the best way to write this?  Please reply with actual code.
    I could use 3 internal tables, where the second 2 use "FOR ALL ENTRIES" to obtain the additional data.  But then how do I append the 2 internal tables back to the first?  I've been told it's bad practice to use nested loops as well.
    Thanks.

    Hi,
    in your case having 2 internal table to update the one internal tables.
    do the following steps:
    *get the records from tables
    sort: itab1 by key field,  "Sorting by key is very important
          itab2 by key field.  "Same key which is used for where condition is used here
    loop at itab1 into wa_tab1.
      read itab2 into wa_tab2     " This sets the sy-tabix
           with key key field = wa_tab1-key field
           binary search.
      if sy-subrc = 0.              "Does not enter the inner loop
        v_kna1_index = sy-tabix.
        loop at itab2 into wa_tab2 from v_kna1_index. "Avoiding Where clause
          if wa_tab2-keyfield <> wa_tab1-key field.  "This checks whether to exit out of loop
            exit.
          endif.
    ****** Your Actual logic within inner loop ******
       endloop. "itab2 Loop
      endif.
    endloop.  " itab1 Loop
    Refer the link also you can get idea about the Parallel Cursor - Loop Processing.
    http://wiki.sdn.sap.com/wiki/display/Snippets/CopyofABAPCodeforParallelCursor-Loop+Processing
    Regards,
    Dhina..

  • Best way to write an Wrapper class around a POJO

    Hi guys,
    What is the best way to write an Wrapper around a Hibernate POJO, given the latest 2.2 possibilities? The goal is, of course, to map 'regular' Java Bean properties to JavaFX 2 Properties, so that they can be used in GUI.
    Thanks!

    what about this:
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.property.StringProperty;
    public class PersonPropertyWrapper {
         private StringProperty firstName;
         private StringProperty lastName;
         private Person _person;
         public PersonPropertyWrapper(Person person) {
              super();
              this._person = person;
              firstName = new SimpleStringProperty(_person.getFirstName()) {
                   @Override
                   protected void invalidated() {
                        _person.setFirstName(getValue());
              lastName = new SimpleStringProperty(_person.getLastName()) {
                   @Override
                   protected void invalidated() {
                        _person.setLastName(getValue());
         public StringProperty firstNameProperty() {
              return firstName;
         public StringProperty lastNameProperty() {
              return lastName;
         public static class Person {
              private String firstName;
              private String lastName;
              public String getFirstName() {
                   return firstName;
              public void setFirstName(String firstName) {
                   this.firstName = firstName;
              public String getLastName() {
                   return lastName;
              public void setLastName(String lastName) {
                   this.lastName = lastName;
         public static void main(String[] args) {
              Person p = new Person();
              p.setFirstName("Jim");
              p.setLastName("Green");
              PersonPropertyWrapper wrapper = new PersonPropertyWrapper(p);
              wrapper.firstNameProperty().setValue("Jerry");
              System.out.println(p.getFirstName());
    }Edited by: 906680 on 2012-7-27 上午10:56

  • Hi just want to know where is the best way to type the statement?

    just to ask you what is the best way to write the statement please

    Could you please explain what the topic and statement is about?
    Helps to narrow the focus, down to a specific hardware or software
    question pertaining to the Apple products involved, where applicable.
    Basic word processing can be accomplished in TextEdit, if you do
    not have Pages or any other software to write with, for example.
    Yet, there is no indication of the purpose, direction, or problem.
    Good luck & happy computing!

  • Best way to write Pl/Sql

    Dear all,
    Can someone say the best way writing below stored proc:
    procedure missing_authorized_services is
    v_truncate_sql varchar2(200);
    v_sql varchar2(2000);
    BEGIN
    v_truncate_sql := 'truncate table missing_authorized_services';
         execute immediate v_truncate_sql;
         commit;
    v_sql := 'INSERT into missing_authorized_services select distinct trim(service_group_Cd) as service_group_Cd, trim(service_cd) as service_cd from stage_1_mg_service_request
    where (service_group_cd, service_cd) not in (
                        select distinct service_group_cd, service_cd from stage_3_servcd_servgrp_dim)';
    execute immediate v_sql;
         commit;
    END missing_authorized_services;
    /* I am doing select from table and then try to Insert into a different table the result set */
    Please guide,
    Thanks
    J

    Hi,
    The best way to write PL/SQL (or any code) is in very small increments.
    Start with a very simple procedure that does something (anything), just enough to test that it's working.
    Add lots of ouput statments so you can see what the procedure is doing. Remember to remove them after testing is finished.
    For example:
    CREATE OR REPLACE procedure missing_authorized_services IS
            v_truncate_sql  VARCHAR2 (200);
    BEGIN
         v_truncate_sql := 'truncate table missing_authorized_services';
         dbms_output.put_line (  v_truncate_sql
                        || ' = v_truncate_sql inside missing_authorized_services'
    END      missing_authorized_services;If you get any errors (for example, ORA-00955, becuase you're trying to give the same name to a procedure that you're already using for a table), then fix the error and try again.
    When it worls perfectly, then add another baby step. For example, you might add the one line
    EXECUTE IMMEDIATE v_truncate_sql;and test again.
    Don't use dynamic SQL (EXECUTE IMMEDIATE) unless you have to.
    Is there any reason to use dynamic SQL for the INSERT?

  • What's the best way for reading this binary file?

    I've written a program that acquires data from a DAQmx card and writes it on a binary file (attached file and picture). The data that I'm acquiring comes from 8 channels, at 2.5MS/s for, at least, 5 seconds. What's the best way of reading this binary file, knowing that:
    -I'll need it also on graphics (only after acquiring)
    -I also need to see these values and use them later in Matlab.
    I've tried the "Array to Spreadsheet String", but LabView goes out of memory (even if I don't use all of the 8 channels, but only 1).
    LabView 8.6
    Solved!
    Go to Solution.
    Attachments:
    AcquireWrite02.vi ‏15 KB
    myvi.jpg ‏55 KB

    But my real problem, at least now, is how can I divide the information to get not only one graphic but eight?
    I can read the file, but I get this (with only two channels):
    So what I tried was, using a for loop, saving 250 elements in different arrays and then writing it to the .txt file. But it doesn't come right... I used 250 because that's what I got from the graphic: at each 250 points it plots the other channel.
    Am I missing something here? How should I treat the information coming from the binary file, if not the way I'm doing?
    (attached are the .vi files I'm using to save in the .txt format)
    (EDITED. I just saw that I was dividing my graph's data in 4 just before plotting it... so It isn't 250 but 1000 elements for each channel... Still, the problem has not been solved)
    Message Edited by Danigno on 11-17-2008 08:47 AM
    Attachments:
    mygraph.jpg ‏280 KB
    Read Binary File and Save as txt - 2 channels - with SetFilePosition.vi ‏14 KB
    Read Binary File and Save as txt - with SetFilePosition_b_save2files_with_array.vi ‏14 KB

  • Whats the best way to expose this in memory database? (ArrayList)

    Hello everyone.
    I was looking for advice on how I should implement this...currently I have the following ArrayList that stores ClassEntity objects. I'm going to write 2 classes that need to access this ClassEntity Object arrayList because they are goign to use these objects to spit out 2 different files.
    I didn't want to make the database public and static though.
    Here's a snippet of my current class that populates and creates the arrayList data structure:
    public class RODMFileParser
         //used to keep file information
         ClassEntity classEntity = null;
         //used to store ClassEntity objects
         List<ClassEntity> classEntityList = new ArrayList<ClassEntity>();
         //used to store the conversion table RODM->ENGLISH/ENGLISH->RODM
         ConversionTableParser convTableParser = new ConversionTableParser();
            else if(line.contains("Field Value "))
                        //now we can create a new Entity Class object! tricky! huh
                        classEntityList.add(new ClassEntity(idClassName,  idFieldName,
                                                                       englishClassName, englishFieldName, fieldType));
    Iterator listIter = classEntityList.iterator();
              while(listIter.hasNext())
                   ClassEntity tempObj = (ClassEntity) listIter.next();
                   System.out.println(tempObj);
              }So now classEntityList has all the objects I need to create these 2 seperate files but these 2 files are dramtically different. What would be the best way at exposing this classEntityList ArrayList so my 2 other classes can access it?
    Thanks!

    well if I made it non-static, wouldn't I have to create a new object of that class in each class I want to use it in?
    for example, that class that populates the database must parse a file to create the database.
    RODMFileParser file = new RODMFileParser();
              file.parseFile("QAGENT");So inside each class I would have to do this wouldn't I? if I made it public static, wouldn't I only have to read to the disk once?
    Putting it to a worst case say, 100 classes need this database, that means I would have to make 100 accesses to the disk woulnd't it?
    And if it was public static, it would jsut return a copy of the database that was only read from the disk once or am I misunderstanding how it works?

  • What is the best way for this situation?

    Hi I have an xml file in my application. over a period of time i have to add few nodes to the existing xml file.
    In my business logic when a specific requirement is met i have to add one child node to the existing parent node for an existing xml file.
    what is the best way to do this? which api is the best for this?

    DrClap wrote:
    Muralidhar wrote:
    using DOM parser we can parse the xml file but can we write to XML file?Sure. That's the inverse operation of parsing, and it's called "serializing".
    The usual way to serialize a DOM to a file is to create a Transformer and apply the identity transformation to the DOM. However there are also third-party XML serializers that don't take that approach.I have not understood what the identity transformation mean. but i have searched for an example and found the following way to do it using Transformer. I hope what i find is right.
    Transformer tFormer = TransformerFactory.newInstance().newTransformer();
              tFormer.setOutputProperty(OutputKeys.METHOD, "xml");
              Source source = new DOMSource(doc);
              Result result = new StreamResult(new File(url.toURI()));
              tFormer.transform(source, result);

  • When I send a webpage via email, some of my recipients are unable to see it properly. The website was made with iWeb, and a Mac person advised me this was the best way to do an email campaign with iWeb, but it's not working for a lot of my customers - why

    I have recently created a website for my family's business. When we bought the Macbook the guy in Apple said the best way to send an email campaign to our mailing list was to publish a hidden page, find it in the browser on Safari, then share it via email, so that is what I do. For most of my customers this works fine, however I have a number of people each month who cannot see any of the content of the email. I have added an 'If you can't see this email properly...' link at the top of the page, with no shapes or images etc near it, but even that does not appear for them.
    I am a self-taught novice unfortunately, so haven't a clue what the problem is. I'm not sure of the operating system, but we bought the Macbook in May and it has all the recent updates installed. I have just had a new baby so can't get into the store fdor a one-to-one, so if anyone could explain why this happens / what I can do about it, I would be very grateful! Thanks!

    If you think getting your web pages to appear OK in all the major browsers is tricky then dealing with email clients is way worse. There are so many of them.
    If you want to bulk email yourself, there are apps for it and their templates will work in most cases...
    http://www.iwebformusicians.com/Website-Email-Marketing/EBlast.html
    This one will create the form, database and send out the emails...
    http://www.iwebformusicians.com/Website-Email-Marketing/MailShoot.html
    The alternative is to use a marketing service if your business can justify the cost. Their templates are tested in all the common email clients...
    http://www.iwebformusicians.com/Website-Email-Marketing/Email-Marketing-Service. html
    "I may receive some form of compensation, financial or otherwise, from my recommendation or link."

  • I have an old 30" apple cinema display (2005) I want to use as a 2nd monitor to a new iMac (2012).  I don't just want mirror image of iMac; what's the best way to do this?

    I have not bought the iMac yet but will do so very soon and just want to make sure I have what I need to get everything setup including adding the old faithful 2005 30" cinema display.  Currently I am driving the old 30" cinema display with a macbook pro also purchased 2005 and happy to say I got a lot of good miles out of this rig.  What's the best way to connect the old 30" monitor as a second display for the new generation iMacs?
    Other Questions
    I can find online new in unopened box a 2012 iMac 27" i7 with 1T Fusion Drive for $1899 no sales tax.  This seems like a pretty good deal since I notice the same is available from Apple refurbished for $100 more plus sales tax.  I know that they say the Fusion drive is a lot faster on 2013 models but some of the speed tests I reviewed online showed the 2012 i7 and 2013 i7 very close on speed for both storage and processing.  Any thoughts?
    I don't like changing batteries so I would buy a separate Apple keyboard with numeric pad since it only comes with wireless keyboard.  I'm a trackpad enthusiast having been using my macbook pro trackpad with current set up; and I am prepared to buy the Apple trackpad and replace batteries every 2 months but I would greatly prefer USB connection and rechargeable trackpact.  I know Logitech makes one so if anyone is using and knows how it compares to Apple's I'm all ears. 

    <http://support.apple.com/kb/HT5891>
    You can use USB for the Apple trackpad.
    <http://www.mobeetechnology.com/the-power-bar.html>

Maybe you are looking for