Cfqueryparam numeric help - is this the best way

I have an update in one of my programs and I'm using the
cfqueryparam. It works fine if the value is not entered since the
type is cf_sql_varchar. If the value is cf_sql_integer/cf_sql_float
and the field is required, it again works fine. Now if the field is
cf_sql_integer and not required, it will throw an error if no value
is passed to it. I tried using the NULL parameter, but that will
put NULL in the field every time. I finally ended up using a cfif
statement to check. Is this the best way? Am I missing something?
How do others handle this?

Your's is as good a way as any. But since you asked, my
approach is usually like this:
Step 1, build a string variable called sql. Perform all your
if/else and other logic at this step.
Step 2
<cfquery>
#PreserveSingleQuotes(sql)#
</cfquery>
My method makes it almost impossible to use cfqueryparam
because of all the quotes. However, I find it easier to develop,
read, and maintain code when you have as much if/else, loop, etc
processing in the same block of code.
You might be able to do both. Something like
Step 1 - use if/else logic to set a variable (call it null)
to either yes or no.
Step 2
cfqueryparam null="#null#">
I've never actually tried. Most of my work is with a db that
does not support cfqueryparam so using it is not a high priority
item for me.

Similar Messages

  • Is this the best way to measure the speed of an input stream?

    Hi guys,
    I have written the following method to read the source of a web page. I have added the functionality to calculate the speed.
    public StringBuffer read(String url)
            int lc = 0;
            long lastSpeed = System.currentTimeMillis();
            //string buffer for reading in the characters
            StringBuffer buffer = new StringBuffer();
            try
                //try to set URL
                URL URL = new URL(url);
                //create input streams
                InputStream content = (InputStream) URL.getContent();
                BufferedReader in = new BufferedReader(new InputStreamReader(content));
                //in line
                String line;
                //while still reading in
                while ((line = in.readLine()) != null)
                    lc++;
                    if ((lc % _Sample_Rate) == 0)
                        this.setSpeed(System.currentTimeMillis() - lastSpeed);
                        lastSpeed = System.currentTimeMillis();
                    //add character to string buffer
                    buffer.append(line);
            //catch errors
            catch (MalformedURLException e)
                System.out.println("Invalid URL - " + e);
            catch (IOException e)
                System.out.println("Invalid URL - " + e);
            //return source
            return buffer;
        }Is it faster to read bytes rather than characters?
    This method is a very important part of my project and must be as quick as possible.
    Any ideas on how I can make it quicker? Is my approach to calculating the speed the best way to it?
    Any help/suggestions would be great.
    thanks
    alex

    sigh
    reading bytes might be slightly faster than reading chars, since you don't have to do the conversion and you don't have to make String objects. Certainly, you don't want to use readLine. If you're using a reader, use read(buf, length, offset)
    My suggestion:
    Get your inputstream, put a bufferedInputStream over it, and use tje loadAll method from my IOUtils class.
    IOUtils is given freely, but please do not change its package or submit this as your own work.
    ====
    package tjacobs;
    import java.awt.Component;
    import java.io.*;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import javax.swing.JOptionPane;
    public class IOUtils {
         public static final int DEFAULT_BUFFER_SIZE = (int) Math.pow(2, 20); //1 MByte
         public static final int DEFAULT_WAIT_TIME = 30 * 1000; // 30 Seconds
         public static final int NO_TIMEOUT = -1;
         public static final boolean ALWAYS_BACKUP = false;
         public static String loadTextFile(File f) throws IOException {
              BufferedReader br = new BufferedReader(new FileReader(f));
              char data[] = new char[(int)f.length()];
              int got = 0;
              do {
                   got += br.read(data, got, data.length - got);
              while (got < data.length);
              return new String(data);
         public static class TIMEOUT implements Runnable {
              private long mWaitTime;
              private boolean mRunning = true;
              private Thread mMyThread;
              public TIMEOUT() {
                   this(DEFAULT_WAIT_TIME);
              public TIMEOUT(int timeToWait) {
                   mWaitTime = timeToWait;
              public void stop() {
                   mRunning = false;
                   mMyThread.interrupt();
              public void run () {
                   mMyThread = Thread.currentThread();
                   while (true) {
                        try {
                             Thread.sleep(mWaitTime);
                        catch (InterruptedException ex) {
                             if (!mRunning) {
                                  return;
         public static InfoFetcher loadData(InputStream in) {
              byte buf[] = new byte[DEFAULT_BUFFER_SIZE]; // 1 MByte
              return loadData(in, buf);
         public static InfoFetcher loadData(InputStream in, byte buf[]) {
              return loadData(in, buf, DEFAULT_WAIT_TIME);
         public static InfoFetcher loadData(InputStream in, byte buf[], int waitTime) {
              return new InfoFetcher(in, buf, waitTime);
         public static String loadAllString(InputStream in) {
              InfoFetcher fetcher = loadData(in);
              fetcher.run();
              return new String(fetcher.buf, 0, fetcher.got);
         public static byte[] loadAll(InputStream in) {
              InfoFetcher fetcher = loadData(in);
              fetcher.run();
              byte bytes[] = new byte[fetcher.got];
              for (int i = 0; i < fetcher.got; i++) {
                   bytes[i] = fetcher.buf;
              return bytes;
         public static class PartialReadException extends RuntimeException {
              public PartialReadException(int got, int total) {
                   super("Got " + got + " of " + total + " bytes");
         public static class InfoFetcher implements Runnable {
              public byte[] buf;
              public InputStream in;
              public int waitTime;
              private ArrayList mListeners;
              public int got = 0;
              protected boolean mClearBufferFlag = false;
              public InfoFetcher(InputStream in, byte[] buf, int waitTime) {
                   this.buf = buf;
                   this.in = in;
                   this.waitTime = waitTime;
              public void addInputStreamListener(InputStreamListener fll) {
                   if (mListeners == null) {
                        mListeners = new ArrayList(2);
                   if (!mListeners.contains(fll)) {
                        mListeners.add(fll);
              public void removeInputStreamListener(InputStreamListener fll) {
                   if (mListeners == null) {
                        return;
                   mListeners.remove(fll);
              public byte[] readCompletely() {
                   run();
                   return buf;
              public int got() {
                   return got;
              public void run() {
                   if (waitTime > 0) {
                        TIMEOUT to = new TIMEOUT(waitTime);
                        Thread t = new Thread(to);
                        t.start();
                   int b;
                   try {
                        while ((b = in.read()) != -1) {
                             if (got + 1 > buf.length) {
                                  buf = expandBuf(buf);
                             buf[got++] = (byte) b;
                             int available = in.available();
                             if (got + available > buf.length) {
                                  buf = expandBuf(buf);
                             got += in.read(buf, got, available);
                             signalListeners(false);
                             if (mClearBufferFlag) {
                                  mClearBufferFlag = false;
                                  got = 0;
                   } catch (IOException iox) {
                        throw new PartialReadException(got, buf.length);
                   } finally {
                        buf = trimBuf(buf, got);
                        signalListeners(true);
              private void setClearBufferFlag(boolean status) {
                   mClearBufferFlag = status;
              public void clearBuffer() {
                   setClearBufferFlag(true);
              private void signalListeners(boolean over) {
                   if (mListeners != null) {
                        Iterator i = mListeners.iterator();
                        InputStreamEvent ev = new InputStreamEvent(got, buf);
                        //System.out.println("got: " + got + " buf = " + new String(buf, 0, 20));
                        while (i.hasNext()) {
                             InputStreamListener fll = (InputStreamListener) i.next();
                             if (over) {
                                  fll.gotAll(ev);
                             } else {
                                  fll.gotMore(ev);
         public static interface InputStreamListener {
              public void gotMore(InputStreamEvent ev);
              public void gotAll(InputStreamEvent ev);
         public static class InputStreamEvent {
              public int totalBytesRetrieved;
              public byte buffer[];
              public InputStreamEvent (int bytes, byte buf[]) {
                   totalBytesRetrieved = bytes;
                   buffer = buf;
              public int getBytesRetrieved() {
                   return totalBytesRetrieved;
              public byte[] getBytes() {
                   return buffer;
         public static void copyBufs(byte src[], byte target[]) {
              int length = Math.min(src.length, target.length);
              for (int i = 0; i < length; i++) {
                   target[i] = src[i];
         public static byte[] expandBuf(byte array[]) {
              int length = array.length;
              byte newbuf[] = new byte[length *2];
              copyBufs(array, newbuf);
              return newbuf;
         public static byte[] trimBuf(byte[] array, int size) {
              byte[] newbuf = new byte[size];
              for (int i = 0; i < size; i++) {
                   newbuf[i] = array[i];
              return newbuf;

  • BC4J datatags: is this the best way to do this?

    In my BC4J JSP application, in the DataTableComponent.jsp, I want to check
    if a property exists on the view object. This is the best way I could come
    up with:
    String PropertyValue =
    (String)dsBrowse.getApplicationModule()
    .findViewObject(dsBrowse.getViewObjectName())
    .getProperty("PropertyName");
    Is this the proper way to get at a view property? Seems like it should be more straightforward.
    Also, does an instance of the ViewImpl class get automatically created when the DataSource tag is used or do you have to specifically instantiate it if you want to use a client method on the view?
    Thanks,
    Steve

    You can do:
       String propVal = dsBrowse.getRowSet().getViewObject().getProperty("PropName");You do not have to instantiate any classes on your own to accomplish this.

  • Is this the best way to redirect using servlet?

    I making a servlet application where the user sends some FORM value to a servlet. I want the servlet to redirect to the answer page after processing the page. Do you think the following code is the correct way of doing?
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            String dnaText = request.getParameter("dnaText");
            /*Getting the tranlated output from dnaToRna method*/
            String finalVal = null;
            String link="http://www.mail.yahoo.com";
            try{
                 finalVal = String.valueOf(dnaToRna(dnaText));
                 response.sendRedirect(link);
                }catch(Exception ex){}
        }

    Many thanks for replying.
    My output file have lots of html code and I dont want to make my servlet heavy with unnecessary code. So I have decided to use another page result.jsp as output file. In result.jsp I intend to call these objects which is storing the value here to display the result.
    As I am new to jsp. I am still in the processing of thinking the best way to handle errors. I have created a method which takes in int values and returns corresponding String values. Like this
    public class DnaToRna extends HttpServlet {
       String error=" * NULL *";
    private String printError(int i) {
            if(i==1){
                error = "There is an error in String to char array";
            }else if (i==2){
                error = "There is an error in your DNA sequence";
            return error;
        }Since error is declared as a class object, if there is no error then I think it should rerun the String NULL. Which can be used to tell people if there is no error. On the contrary if there is really an error, I can use this to tell what is exactly causing the error.
    Although I am new to web programing. I think this would be nice.
    Here is the other method
    public String dnaToRna (String dnaText) throws Exception{
                /*Trim()*/
                dnaText = dnaText.trim();
                /*Codes for Dna to Rna translation*/
                if(Pattern.matches(".*[^atgc]+.*",dnaText))
                return printError(2);
                return dnaText.replaceAll("t","u");
                }

  • Is This The Best Way To Put iMovie Effects On An FCE Clip?

    I have often suggested to other people that they should export clips from FCE to iMovie in order to make use of certain iMovie effects that FCE can't do.
    As with most things there are several different ways of "transporting" the clips.
    Bearing in mind that we want the quickest/lossless method possible, is this the best?
    1. In the FCE Timeline double-click the clip.
    2. Select File>Export>QuickTime Movie and click "Save".
    3.Open a new iMovie Project, import the newly made QuickTime Movie clip and add the necessary effect.
    4. Back in FCE, Import the QuickTime Movie from the iMovie Project.
    Is this in fact the best way or do you know of a better/quicker one?
    Ian.

    Thanks for the confirmation, Tom.
    By "clip" I was actually meaning a few seconds of video I had chopped up on the timeline.
    What caught me out initially was when I simply highlighted the 10 second "clip" and selected QuickTime Movie.
    The estimated time for conversion was around 10 minutes! It was actually making a QT Movie of the complete Sequence, not just the selected "clip". I soon realised that the "clip" needed double-clicking to ensure that only the required 10 seconds were converted.
    Ian.

  • Adding buttons to multiple frames -- is this the best way to do this?

    In CS5, I want to create a series of buttons that when clicked will linked to other frames in the same timeline. So one button will link to frame 5, one will link to frame 10, one will link to 15, etc. All the buttons will appear across the top of the stage on a layer, and I want them to appear on all of the frames so the user can click back-and-forth to the different frames/screens.
    1. Is the best way to do this to just add the buttons to frame 1 and add a keyframe to the last frame in the timeline, frame 15, so they are copied to all the frames in between?
    2. Are there any issues with doing it this way?
    Thanks!!!

    Just have the one keyframe in frame 1 and extend it to frame 15.  You do not need/want another keyframe at frame 15.

  • MouseOver is this the best way?

    I'm trying to create mouse over (tool tip) for everything in
    my simulated control panel my question is, is mouseOver event
    handler the best way to have the program display a small amout of
    text over the mouse pointer. seems to me this is done all the time
    and there should be a better way.
    thank you in advance for your help

    kglad i agree on the Array way i have many buttons, lights,
    vents,......... that i want tool tips for so i will do the Array.
    another dumb question what is bubbling i did not see a differance
    when i tried MOUSE or ROLL.
    i thought
    Knobtip.x = this.mouseX;
    Knobtip.y = this.mouseY;
    would make the tip follow the mouse pointer.
    thanks again guys i'm taking a 5 day class in 2 weeks so i
    will not (hopefully) ask so many stupid questions

  • Do I get better results/ keeping the battery's life longer by charging only when it comes to 5-10% or should I let it empty and then charge it? Someone told me also to turn it off while I charge it... So help what is the best way to keep long life battery

    I got the new iPad on June 2012 and I wish to keep the long life of the battery as much as I can. I always and only use the cable that comes with the product and never charge it through computer.
    Should I:
    1) wait till baterry is completely empty, pratectly dead and then charge it?
    2) charge it when it reach 5%-10%.
    3) turn off the iPad when I charge the battery?
    Thank you apple support :)

    The quickest way (and really the only way) to charge your iPad is with the included 10W USB Power Adapter. iPad will also charge, although more slowly, when attached to a computer with a high-power USB port (many recent Mac computers) or with an iPhone Power Adapter (5W). When attached to a computer via a standard USB port (most PCs or older Mac computers) iPad will charge very slowly (but iPad indicates not charging). Make sure your computer is on while charging iPad via USB. If iPad is connected to a computer that’s turned off or is in sleep or standby mode, the iPad battery will continue to drain.
    Apple recommends that once a month you let the iPad fully discharge & then recharge to 100%.
    How to Calibrate Your Mac, iPhone, or iPad Battery
    http://www.macblend.com/how-to-calibrate-your-mac-iphone-or-ipad-battery/
    At this link http://www.tomshardware.com/reviews/galaxy-tab-android-tablet,3014-11.html , tests show that the iPad 2 battery (25 watt-hours) will charge to 90% in 3 hours 1 minute. It will charge to 100% in 4 hours 2 minutes. The new iPad has a larger capacity battery (42 watt-hours), so using the 10W charger will obviously take longer. If you are using your iPad while charging, it will take even longer. It's best to turn your new iPad OFF and charge over night. Also look at The iPad's charging challenge explained http://www.macworld.com/article/1150356/ipadcharging.html
    Also, if you have a 3rd generation iPad, look at
    Apple: iPad Battery Nothing to Get Charged Up About
    http://allthingsd.com/20120327/apple-ipad-battery-nothing-to-get-charged-up-abou t/
    Apple Explains New iPad's Continued Charging Beyond 100% Battery Level
    http://www.macrumors.com/2012/03/27/apple-explains-new-ipads-continued-charging- beyond-100-battery-level/
    New iPad Takes Much Longer to Charge Than iPad 2
    http://www.iphonehacks.com/2012/03/new-ipad-takes-much-longer-to-charge-than-ipa d-2.html
    Apple Batteries - iPad http://www.apple.com/batteries/ipad.html
    Extend iPad Battery Life (Look at pjl123 comment)
    https://discussions.apple.com/thread/3921324?tstart=30
    New iPad Slow to Recharge, Barely Charges During Use
    http://www.pcworld.com/article/252326/new_ipad_slow_to_recharge_barely_charges_d uring_use.html
    Tips About Charging for New iPad 3
    http://goodscool-electronics.blogspot.com/2012/04/tips-about-charging-for-new-ip ad-3.html
    Prolong battery lifespan for iPad / iPad 2 / iPad 3: charging tips
    http://thehowto.wikidot.com/prolong-battery-lifespan-for-ipad
    In rare instances when using the Camera Connection Kit, you may notice that iPad does not charge after using the Camera Connection Kit. Disconnecting and reconnecting the iPad from the charger will resolve this issue.
     Cheers, Tom

  • Is this the best way to Triple Boot?

    Hi all, I have a had a pickle of a time setting up Leopard...with my triple boot setup.
    I am curious if I went about it "properly"or if there is a better way.
    Use instructions at your own peril if you wish. I am not responsible for errors or any problems you may have by using my instructions. This is my individual experience. *I am happy if this works for someone* struggling to set up a triple boot, but am posting this more so to see if there are any improvements to be made, or mistakes that need correcting to this method...
    I had an Intel MBP (SR) with 3 partitions. Tiger, Vista and Ubuntu but when trying to install Leopard it said it would not install and I would have to change my drive to guid partition scheme.
    So, through trial and error this is the only way I could get it to work.Keep in mind I started from scratch with vista and ubuntu, but did make a backup of my tiger drive.
    1. BACK UP
    2. Wipe everything and repartition internal disk to guid partition map and 1 partition. Install Leopard.
    3. Use either disk utility or carbon copy cloner(my purchased copy of SuperDuper is still not able to do what CCC, a free program can do,apparently because they are trying to figure out time machine and are holding up a leopard compat. version, uuughh, but thats a different post...) to clone Leopard to external drive that is set up as GUID partition scheme.Make sure you are able to boot this external.
    4. Wipe internal, repartition to 3 partitions using disk utility and MBR partition scheme in this order from top to bottom(in disk utility partition gui);
      a. Leopard partition: OSX extended journaled
      b. Vista partition: I think there is only one option: maybe Fat? Just make sure you select "windows" format (The vista installer will need to reformat this during install anyway)
      c. Ubuntu partition: "Free Space"
    5. Then to install leopard, (which apparently won't install on a drive set up as MBR partition scheme, but that is what we formatted the internal drive as anyway) clone the external copy of leopard to the internal OSX partition we just made.
    6. Then install vista by booting from install cd. During install you may have to reformat the Windows partition using the windows installer, but it should install fine after that.
    7. Then Install ubuntu using live cd/dvd to the internal free space partition, splitting/ formatting the last partition using the ubuntu install/partition tool on the "manual"partition mode(make sure you are using the correct free space partition. I confirmed this by looking at the sizes of the partitions that showed up): "free space" into root and swap partitions if you want. I used ext2 for root
         *Side note:*If you have the same MBP as me you may have to change some setting when booting the live cd: Once the cd loads and you get to the preliminary menu window, press F6 to edit. A command will show up on the screen: You have to erase the last two words starting at "quiet" till end. Then write "allgenericide" in their space, keeping all of the command before quiet.  then press enter. It should then load to the ubuntu desktop where you can click on the install icon.(this took me a long time to figure out. I have also have to do this everytime I want boot into ubuntu, which stinks. Anyone know how to resolve this? (Linux masters?)
    8. boot into osx and install rEFIt
    Issues:
    1. My Leopard partition is not showing up in OSX's startup disk pane in sys pref. but it is booting/ showing up as if it was, if having trouble, try holding option key during startup.
    2. I have also had a few issues with rEFIt not starting up as default menu, but when holding option key at startup it will show up. Then gives me the option of OSX, Vista or Ubuntu once selected.
    3. And the command thing with ubuntu at every startup I mentioned earlier.Is there a way to write allgenericide as a default or any other way to fix this?
    If anyone has a better way of accomplishing this please let me know. I got to this point through a lot of trial and error and I'm not sure if there is a more stable/better way for a triple boot setup...
    I would like for the Leopard partition to show up as the osx startup disk in the pref pane, but regardless it is still working.
    Correct me if I'm wrong, but it seems boot camp makes the drive into an MBR partition scheme anyway, so I'm curious what others who were already running dual or triple boot, boot camp systems had to do when upgrading their boot camp setups from tiger to leopard. Did it not allow you to install to the MBR partition scheme made by boot camp? Did you have to start from scratch as well?
    Thank you in advance for your patience and support.  

    http://wiki.onmac.net/index.php/TripleBoot_viaBootCampI would install Vista before installing Leopard.
    That has worked better for me anyway.
    And that may make Leopard the default.
    In Vista, AppleControl is under /Windows/SysWOW64 if you ever need to get to it (there is also AppleOSSMgr and AppleTimeSrvc )
    http://wiki.onmac.net/index.php/TripleBoot_viaBootCamp

  • HELP. Whats the best way to save an Illus CS6 as a jpeg to be emailed

    HELP. I've tried saving to web and exporting my file out of Illus CS6 as a jpeg to be emailed.
    I then attached the file to mail and send it. But then cannot download the file! I even send it as windows friendly. I'm not sure what else to do or why the jpeg files are embedding in the email instead of as an attachment.
    Can anyone advise.
    Thanks

    It's different because whomever you are sending email to doesn't understand their email application. Not everyone with access to a computer is savvy enough to understand some of the basics.
    If the images are inline on their end, all then need do is save those inline images the same way they would an attachment.
    On the Mac, you can zip any file by Control-Clicking and and choosing "Compress [filename]"

  • Pl help me with the best way of coding this

    I have a procedure in which there is a varchar2 parameter passed ie p_job . I have to use this parameter in the where clause of the static query.
    If the passing value is '*' then
    IF p_job = '*' THEN
    WHERE JOB IN ('MANAGER', 'CLERK', 'SALESMAN')
    ELSE
    WHERE JOB=p_job
    How to write the query?
    Manjula

    Where job = DECODE(p_job,'*','MANAGER','*','CLERK','*','SALESMAN',p_job) That would give you only the first value from the decode, not the IN list of values that the OP requires.
    SQL> variable p_job varchar2(10)
    SQL>
    SQL> exec :p_job := '*' ;
    PL/SQL procedure successfully completed.
    SQL> select DECODE(:p_job,'*','MANAGER','*','CLERK','*','SALESMAN',:p_job) from dual ;
    DECODE(:P_JOB,'*','MANAGER','*',
    MANAGER
    1 row selected.
    SQL>

  • I need help figuring out the best way to convert analogue video to DV so that I can edit it.

    I have a large number of VHS and hi8 tapes that I want to convert to high quality DV.
    I have a couple of options. One is an Elgado Video capture system.
    The other is a Sony Digital Media Converter Box (DVMC-DA2).
    I have tried a few of the less important tapes using the Elgado Video Capture system. It only allows you to convert to MPEG4 or H.268. It is not very good quality, especially for archival items or items I would later wish to edit.
    I also have the Sony Digital Media Converter Box. I have heard that this is a superior option. So far, though, I have only been able to figure out how to import using an old version of iMovie HD. This makes a large imovie project file (approximately 6.18GB for a 28:30 clip vs a 348.9MB for an MPEG4 using delgado.
    On top of that to convert the file from an iMovieProject file to DV is an additional step that so far looks like will take a half an hour at best.
    Is there any way for me to import VHS/hi8 tapes using the Digital Media Converter Box to creat high quality DV files directly? If so, where can I find this info? What steps should I take and what are the settings I should use.
    I have a lot of tapes so I want to figure out the right and most efficient way to do this because I will be repeating it a bunch of times and would hate to have to start over again.
    I should also mention that I am using a Mid 2010 MacBook Pro, with OSX 10.9.1
    I'm sorry in advance if this seems like an obvious question, but I have been googling and looking at tutorials on the site and just have not found the answer. There are a lot of ads for expensive low quality services to do this converting for you, so maybe the answer I am looking for is burried in all that advertising.
    Thanks

    Thanks Biggles and Gotz. I just couldint find capture, but now I can! (It was right under my nose too).
    I'm trying it now and it appears to be working. Do you have any other recommendations for capturing from hi8 video source as far as setting go? I am using DV to capture. Are there any other settings I should pay attention to?
    There is an extra line of video noise at the bottom, but when I google it, it sounds like it won't show on most standard tvs and if I want to fix it for online, that I should mask it after the fact vs scaling up the video.

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

  • Please Help, What's the best way to un-install Leopard?

    I have a new MBP 17" . I installed Leopard 2 days after I bought the machine, am having so many keyboard problems, like not being able to type and waiting around for the keyboard to start typing. It has now become very annoying and I cannot get any work done! I think I should un-install Leopard and go back to Tiger. How can I do this successfully and without losing any data. I will back up..... If any one has the answer to this it will be great. I also think that apple knows about this issue, and I think it's really bad policy on their part, not to simply say, WE ARE FIXING IT...... In-fact I think it's downright stupid of them!

    What I meant with external backup is either an external hard drive or another mac where you have a copy of all your important files/applications and you should be able to use Migration Assistant with either. If you want to use MA, it will copy all the files (you can't pick and choose), so what I did was simply connect my external hard drive to the new MBP via firewire and copied over whatever I needed. Since I also keep copies of all installer .dmg's (updates or applications) on the external, I copied those over as well and then just installed my (some third party) applications and/or updates. If you don't have an external hard drive, you should also be able to connect your Powerbook and new MBP via ethernet cable and copy your files over. I used that method as well, using my internet ethernet cable (temporarily disconnected from my cable modem) and following the directions under Mac Help -> Filesharing. I've found both the firewire and ethernet methods easy and quick and they worked for me because I wanted to pick which files I wanted to copy to the new machine (rather than all of them).
    I will wait for quite a while before installing Leopard again (if at all); not only because of the keyboard issue, but Disk Utility seems to have some major problems, and so does the System itself (showing up during 20+ minutes of every Permissions Repair with 71 full pages of "ACH found but not expected in..." listing what seems to be every single system file). I also prefer to open the contents of a folder from the dock in alphabetical order, rather than the admittedly cool looking icons - when you have 120+ items/folders in that folder, it's a waste of time to get through all of those icons. And Spaces didn't work for me either. So, except for the cool desktop picture, I wasn't at all impressed with Leopard. However, I did use the included iLife 08 (except iMovie 08) and custom installed that once I had Tiger up and running.

  • Is this the best way to test a prime number?

    Ok so I think I finally got my program to work. I tested It with very big 8 digit prime numbers if that means anything. here are 2 Questions about my program"
    -Is this a way of finding prime numbers? (does the program fulfill its purpose?)
    and Second is there a smarter way of doing it?
    Here is the program:
    //This program tests if a number is a prime number
    import java.util.Scanner;
    public class Main
    public static void main ( String args [ ] )
    Scanner input = new Scanner( System.in );
    int number;
    int bob;
    System.out.print(" Enter the number you wish to test:\n");
    number = input.nextInt();
    if (number == 1)
    System.out.print(" 1 is divisible only by 1, therefore it is not prime or composite\n");
    if (number == 2)
    System.out.print(" It's Prime\n ");
    for ( int test = 2 ; test < number ; test++ )
    bob = number % test;
    if ( bob == 0)
    System.out.print("It's Composite\n");
    return;
    System.out.println("It's Prime");
    }

    I got interested in this ...
    //1. PrimeTester_BruteForce: found 3001134 primes <= 50000000 in 410500 milliseconds
    //2. PrimeTester_SieveOfEratosthenes: found 3001134 primes <= 50000000 in 4422 milliseconds
    //3. PrimeTester_SieveOfAtkin: found 3001134 primes <= 50000000 in 24843 milliseconds
    ... so Wkipedia's SieveOfAtkin algorithm apparently requires some serious optimization before it outruns the Greeks... see http://cr.yp.to/primegen.html for an optimized C implementation (which I can't follow).
    PrimeTester_BruteForce.java//find all prime numbers upto the given maximum.
    //Using the brute force method
    //http://www.newton.dep.anl.gov/newton/askasci/1995/math/MATH039.HTM
    //PrimeTester_BruteForce: found 3001134 primes <= 50000000 in 410500 milliseconds
    import java.io.PrintWriter;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    public class PrimeTester_BruteForce {
         public static void main(String[] argv) throws IOException {
              long start = System.currentTimeMillis();
              PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_BruteForce.txt")));
              int limit = 50000000;
              int count = 0;
    nextn:     for (int n=2; n<=limit; n++) {
                   int top = (int)Math.sqrt(n);
                   for(int i=2; i<=top; i++) {
                        if(n%i==0) {
                             continue nextn;
                   out.print(n);
                   out.print(" ");
                   if(++count%20==0) out.println();
              long took = System.currentTimeMillis()-start;
              out.println();
              out.println("PrimeTester_BruteForce: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
              out.close();
    PrimeTester_SieveOfEratosthenes.java/******************************************************************************
    //find all prime numbers upto the given maximum.
    //http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
    limit = 1000000;       // arbitrary search limit
    // pressume all are prime
    for (i=2; i<=limit; i++) is_prime[i] = true;
    // eliminate multiples of each prime, starting with its square
    for (n=2; n<=sqrt(limit); n++) {
       if (is_prime[n]) {
          for (i=n^2; i<=limit; i+=n) is_prime[i] = false;
    // print the results
    for (n=2; n=<limit; n++) {
      if (is_prime[n]) print(n);
    //PrimeTester_SieveOfEratosthenes: found 164185 primes <= 1000000 in 125 milliseconds
    import java.io.PrintWriter;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    public class PrimeTester_SieveOfEratosthenes {
         public static void main(String[] argv) throws IOException {
              long start = System.currentTimeMillis();
              PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_SieveOfEratosthenes.txt")));
              int limit = 50000000;
              int n, i;
              boolean[] is_prime = new boolean[limit+1];
              // pressume all are prime
              is_prime[2] = true;
              for (i=2; i<=limit; i++) {
                   is_prime[i] = true;
              // eliminate multiples of each prime, starting with its square
              for (n=1; n<=Math.sqrt(limit); n++) {
                   if (is_prime[n]) {
                        for (i=n*2; i<=limit; i+=n) {
                             is_prime[i] = false;
              // print the results
              int count = 0;
              for (n=2; n<=limit; n++) {
                   if (is_prime[n]) {
                        out.print(n);
                        out.print(" ");
                        if(++count%20==0) out.println();
              long took = System.currentTimeMillis()-start;
              out.println();
              out.println("PrimeTester_SieveOfEratosthenes: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
              out.close();
    PrimeTester_SieveOfAtkin.java/******************************************************************************
    //find all prime numbers upto the given maximum.
    //http://en.wikipedia.org/wiki/Sieve_of_Atkin
    limit = 1000000; // Arbitrary search limit
    array is_prime[5:limit] initial false; // Sieve array.
    biginteger x,y,n,k; // Must be able to hold 5*limit: 4x^2 + y^2!
    // put in candidate primes: integers which have an odd number of representations
    // by certain quadratic forms.
    for x:=1:sqrt(limit) do
    for y:=1:sqrt(limit) do
       n:=4x^2 + y^2; if n<=limit and n%12 = 1 or 5 then is_prime[n]:=not is_prime[n];
       n:=3x^2 + y^2; if n<=limit and n%12 = 7 then is_prime[n]:=not is_prime[n];
       n:=3x^2 - y^2; if n<=limit and x>y and n%12 = 11 then is_prime[n]:=not is_prime[n];
    next y;
    next x;
    // eliminate composites by sieving
    // if n is prime, omit all multiples of its square; this is sufficient because
    // composites which managed to get on the list cannot be square-free
    for n:=5:sqrt(limit) do
      if is_prime[n] then for k:=n^2:limit:n^2 do is_prime[k]:=false; next k;
    next n;
    // Present the results.
    print 2, 3; for n:= 5:limit do if is_prime[n] then print n; next n;
    //PrimeTester_SieveOfAtkin: found 441 primes <= 1000000 in 203 milliseconds
    import java.io.PrintWriter;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    public class PrimeTester_SieveOfAtkin {
         public static void main(String[] argv) throws IOException {
              long start = System.currentTimeMillis();
              PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_SieveOfAtkin.txt")));
              int limit = 50000000;
              int sqrt = (int)Math.sqrt(limit);
              boolean[] is_prime = new boolean[limit+1]; // Sieve array.
              int x, y, n, k; // Must be able to hold 5*limit: 4x^2 + y^2!
              // put in candidate primes: integers which have an odd number of representations by certain quadratic forms.
              for (x=1; x<=sqrt; x++) {
                   for (y=1; y<=sqrt; y++) {
                        //n=(4*(x^2)) + y^2; if (n<=limit && n%12 in(1,5)) is_prime[n] = !is_prime[n];
                        int xSq = (int)Math.pow(x,2);
                        int ySq = (int)Math.pow(y,2);
                        n = 4*xSq + ySq;
                        if (n<=limit && (n%12==1||n%12==5)) {
                             is_prime[n]= !is_prime[n];
                             //debug("A: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
                        //n=((3*(x^2)) + y^2; if (n<=limit && n%12==7) is_prime[n] = !is_prime[n];
                        n = 3*xSq + ySq;
                        if (n<=limit && n%12==7) {
                             is_prime[n]= !is_prime[n];
                             //debug("B: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
                             //debug("   if (n<=limit:"+limit+" && n%12:"+(n%12)+"==7");
                             //debug("   (3*(x^2)):"+xSq+" + (y^2):"+ySq);
                        //n=((3*(x^2)) - y^2; if (n<=limit && x>y && n%12==11) is_prime[n]= !is_prime[n];
                        n = 3*xSq - ySq;
                        if (n<=limit && x>y && (n%12==11)) {
                             is_prime[n]= !is_prime[n];
                             //debug("C: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
                   }//next y
              }//next x
              // eliminate composites by sieving
              // if n is prime, omit all multiples of its square; this is sufficient because
              // composites which managed to get on the list cannot be square-free
              // for (n:=5:sqrt(limit)) {
              //   if (is_prime[n]) for (k:=n^2:limit:n^2) is_prime[k]:=false;
              for (n=5; n<=sqrt; n++) {
                   if (is_prime[n]) {
                        int nSq = (int)Math.pow(n,2);
                        for(k=nSq; k<=limit; k+=nSq) {
                             is_prime[k]=false;
                             //debug("D: n="+n+" is_prime["+k+"]="+is_prime[k]);
              // Present the results.
              int count = 2;
              out.print("2 3 ");
              for(n=5; n<=limit; n++) {
                   if(is_prime[n]) {
                        out.format("%d ", n);
                        if(++count%20==0) out.println();
              long took = System.currentTimeMillis()-start;
              out.println();
              out.println("PrimeTester_SieveOfAtkin: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
              out.close();
         //private static void debug(String msg) {
         //     System.out.println(msg);
    }

Maybe you are looking for