How can I press keyboard to play vdo only once!

Hi, I'm here again for your help :{ I have a question which I tried to google it but can't find the answer. Well,..May be there is an answer but I just can't make it works? I'm in a process of learning AS3 so let's say I'm still new here.
What I'm doing is making a keyboatd to respond with the vdo files I have. It is a very simple idea as press-n-play. Each keys has their vdos to play and if you press another button while the first one is still pressing, it'll play another vdo of its key. I have make this as boolean with function of keydown and keyup like this:
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.net.NetStream;
import flash.net.NetConnection;
import flash.media.Video;
var isLeft:Boolean = false;
var isRight:Boolean = false;
var video;
var nc;
var ns;
stage.addEventListener(KeyboardEvent.KEY_DOWN,onDown);
stage.addEventListener(KeyboardEvent.KEY_UP,onUP);
this.addEventListener(Event.ENTER_FRAME,playVid);
                    nc = new NetConnection();
                    nc.connect(null);
                    ns = new NetStream(nc);
                    ns.client = this;
                    video = new Video(550,400);
                    addChild(video);
                    video.attachNetStream(ns);
function onDown(e:KeyboardEvent):void
          switch (e.keyCode)
                    case 37 :
                              //ns.play("TomAndJerry.flv");
                              isLeft=true;
                              break;
                    case 39 :
                              //ns.play("westler.flv");
                              isRight = true;
                              break;
function onUP(e:KeyboardEvent):void
          switch (e.keyCode)
                    case 37 :
                              isLeft = false;
                              break;
                    case 39 :
                              isRight = false;
                              break;
function playVid(e:Event):void
          if (isLeft)
                    trace("kk");
                    ns.play("westler.flv");
                    isLeft = false;
          else if (isRight)
                    trace("PP");
                    ns.play("TomAndJerry.flv");
                    //isRight = false;
I have tried making a keydown function without using any boolean or those true of false things to just play a vdo. It worked but, I still have the same problem that I can't find a solution which is ....
When you hold down the keyboard button the vdo will keep start at the beginning.
All I want is to play the vdo even the key is press down. If the vdo ends then play again as loop but if the key is up the vdo will play until it ends.
And  if there are more than one button are holding down just play the vdo of the lastest pressed button.
T-T"
Thanks.
Ps. I have tried removeEventListener but, it made every buttons' function gone.

Wow! That is the problem like you said.
I have removed it out and try this:
function onDown(e:KeyboardEvent):void
          if (e.keyCode==49)
                    ns.play("GetThere.flv");
                    stage.removeEventListener(KeyboardEvent.KEY_DOWN,onDown);
                    onUP(null);
          if (e.keyCode==69)
                    ns.play("westler.flv");
                    stage.removeEventListener(KeyboardEvent.KEY_DOWN,onDown);
                    onUP(null);
function onUP(e:KeyboardEvent):void
          if(e.keyCode==49)
                    stage.addEventListener(KeyboardEvent.KEY_DOWN,onDown);
          if(e.keyCode==69)
                    stage.addEventListener(KeyboardEvent.KEY_DOWN,onDown);
And it works!
But, then I have an error massage says "
TypeError: Error #1009: Cannot access a property or method of a null object reference.
          at xxx_fla::MainTimeline/onUP()
          at xxx_fla::MainTimeline/onDown()"
May I ask you something?
Will it make me any problem if I load more vdos? Let's say about...20?
Because if it is hard to solve this error and it won't make anything worse (time delay,etc.) then I'm fine with it.
Thanks :}

Similar Messages

  • How can I ensure a function is called only once in a query?

    I have a function (in a package) that returns the start date and end date to be used by my query. The query was taking bind variables but when I updated it to use the function calls it slowed down a lot.
    I tried creating an inline view that selects the start and end date and joins with the other table but this does not help. I thought the inline view would only be run once but this is not the case. I have my function print out a value from a sequence and i see that it is called thousands of times.
    Why would the procedure call be so much slower?
    How can I ensure that the function is only called once in the query?
    This is what I currently have:
    SELECT col1, col2
    FROM aTable,
    (SELECT proc.getStartdate startDate,
    proc.getEndDate endDate
    FROM dual) dt
    WHERE aTable.theDate >= dt.startDate
    AND aTable.theDate <= dt.endDate
    Thanks

    They get the begining and ending dates to be used by the query.
    My application uses the Oracle Portal. Each user can select their date range and it is stored as a user preference. The portal API provides funcitons for retrieving the preferences and I have encapsulated it in my procedure so the developers do not need knowledge of the portal. If they just restrict their queries to the dates returned by this function they will get the needed data.
    Our work around as been to pass these date variables around as bind variables.

  • I have my ipod backed up on multiple computers but only one recognizes all my playlists.  How can I get all my play lists to show up on multiple computers?

    I have my ipod backed up on multiple computers but only one computershows all my playlists.  How can I get all my play lists to show up on multiple computers?

    If you want to connect and use an iPod on more than one computer you need to change the update preference in the iPod Summary tab to "Manually manage music and videos" and click Apply.
    Using iPod with Multiple computers
    Managing content manually on iPod
    If your iPod is set to update automatically take care when connecting to a different computer if your current one is out of commission. You will get a message that your iPod is linked to a different library and asking if you want to link to this one and replace all your songs etc, press "Cancel". Pressing "Erase and Sync" will irretrievably remove all songs from your iPod. Your iPod should appear in the iTunes source list from where you can change the update setting to manual and use your iPod without the risk of accidentally erasing it.

  • How can I get audio to play from my TV when using hdmi cable?  Video looks great, just no sound.

    How can I get audio to play from my TV when using hdmi cable?  Video looks great, just no sound.
    I've tried plugging the hdmi into the TV directly and the receiver.
    I get video every time.  HBO to Go , Xfinity, ABC, Youtube, etc...
    just no audio.  Any suggestions? 
    I've tried starting the apps then plugging in the hdmi cable.
    I never tried this before I upgraded to IOS 5.

    Claudiamil-
    I had not tried it with mine since upgrading to iOS 5, so I just did.  I'm using a small Vizio HDTV.  I did not try YouTube, but did try several videos and musical numbers.  In all cases there was sound, including stereo when the source had it.
    I assume you are getting sound from the iPad when the adapter is not connected, so the volume is not turned down.  Dah*veed's suggestion to reset may be what you need.
    Fred

  • How can I watch a DVD playing on my iMac on my TV using Apple TV?

    How can I watch a DVD playing on my iMac on my TV using Apple TV?

    You can't. The only way is to transfer the movie to your computer and import to iTunes (making sure it is compatible) and either use home-sharing or airplay the movie off an ios device.

  • TS1717 I just downloaded a song and it only plays the first 50 seconds and then moves to the next song in the list. How can I get it to play the rest of the song?

    I just downloaded a song and it only plays the first 50 seconds and then moves to the next song in the list. How can I get it to play the rest of the song?

    If your country's iTunes Store allows you to redownload purchased tracks, I'd delete your current copy of the track and try redownloading a fresh one. See the following document for instructions:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    Otherwise, I'd report the problem to the iTunes Store.
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the item that is not playing properly. If you can't see "Report a Problem" next to the item, click the "Report a problem" button. Now click the "Report a Problem" link next to the item.

  • How can I make music (mp3) play automatically in one Scene (NO buttons)?

    How can I make an mp3 play automatically in one Scene (NO buttons)? I have been searching the net for answers for over 10 hours with no answer... My movie will not be for the web, it needs to be portable (CD or flash drive)...
    PLEASE HELP!!!!!!!
    thank you!

    You just need to look in Help for the Sound class and possibly SoundChannel... if you have an MP3 in your library - right click it, and go to properties. Set the sound to export for ActionScript - and give it a class name - mySound will work. Then you can make it play with something as simple as:
    var a:SoundChannel = new mySound().play();

  • Play a song from itunes? it will show the art work then skip three or four songs and start playing! How can I get it to play the songs I touch? This is a new phone but has been restored from backup. Not even all my icloud music is showing

    play a song from itunes? it will show the art work then skip three or four songs and start playing! How can I get it to play the songs I touch? This is a new phone but has been restored from backup. Not even all my icloud music is showing

    Hi amorg1876,
    If your iPhone is skipping over certain songs, you may want to check out this article:
    Troubleshooting songs that skip
    http://support.apple.com/kb/TS3217
    Cheers!
    - Ari

  • I recorded VCR tape onto DVD-R but will not play on my MacBook Pro. I have already recorded multiple DVDs. How can I get it to play on my Mac?

    I recorded VCR tape onto DVD-R but will not play on my MacBook Pro. I have already recorded multiple DVDs. How can I get it to play on my Mac?

    "I recorded VCR tape onto DVD-R"
    How? Using what equipment/software?
    "The DVD  plays on the device on which it was recorded."
    Just a guess: You're using a VCR-DVD combo recorder. DVDs produced in this way will play on the device that made them, but won't play on anything else until they're "finalized." In fact, Macs will recognize unfinalized DVDs as blank discs until the discs are finalized. Check the manual that came with the recording device for instructions.

  • I recently purchased QuickTime 7 Pro to convert avi files to mov files for editing on Imovie. However, QuickTime won't play the files. How can I get them to play and how can I convert them to mov files?

    I recently purchased QuickTime 7 Pro to convert avi files to mov files for editing on Imovie. However, QuickTime won't play the files. How can I get them to play and how can I convert them to mov files?

    I recently purchased QuickTime 7 Pro to convert avi files to mov files for editing on Imovie. However, QuickTime won't play the files. How can I get them to play and how can I convert them to mov files?
    Both the AVI and the MOV file extensions refer to the file container and not the compressed data the file contains. Both are generic file containers in that each may contain any valid combination of audio and/or video data that is compatible with the codec component configuration of the system on which the file was created. On the other hand, whether a file is playback compatible, conversion compatible, and/or edit compatible depends on the data actually contained in the file container. So, you are basically dealing with two separate issues here—the container and what is inside it.
    Basically, if you want to make your files ediit compatible with iMovie, you must change your file container to one that is acceptable to iMovie and convert the data to edit compatible audio and/or video compression formats as may be necessary. The best approach is to determine what codecs were actually used to create the original AVI files and add them to your system if possible. In most cases a codec package like Perian can be added to your system's codec component configuration to may the AVI file playable. Once they are playable, in the QT 7 app then they can be chnged or converted to file types and compression formats that can be edited in iMovie. (While Perian handles most codecs commonly used to create AVI files, it does not handle all possibilities and, while the Perian codec package still works under cureent Mac OS versions, its development group has decided to drop further development/support of the package.)
    Background: AVI is a file container originally developed by Microsoft back in 1992 but for which official support was discontinued about 11 years. Despite its limitations, Windows users still tend to use this file based on its open source ease of use and generic nature, thus, making its use so popular that most users are unwilling to switch to more modern but less generic file types. Since some AVI legacy compression formats have never been transcoded for the Mac or use beyond OS 9 or OS X PPC platforms, it is often important to know what specific compression formats are contained in the AVI file to know which codecs to add to your system and which not to add in order to avoid possible codec conflicts.
    You can use many different converters to convert AVI files to iMovie edit compatible files. Most third-party apps contain their own buit-in codecs which do not relay on the Mac codec component configuration. Free ones, like HandBrake, usually have limited conversion capabilities while those that have more varied outputs are usually commercial in nature and will cost you additional cash. QT 7 Pro or the free MPEG Streamclip app allow you to access you own system's component configuration and use any available codec component like DV, AIC, MPEG-4, H.264, Photo JPEG, etc.—all of which are iMovie compatible for editing purposes—but only after making the AVI file QT 7 player compatible.
    In order to determine what compression formats wewre used in your AVI files you can
    1) Try checking the Finder "Info" window,
    2) Use the "Inspector", "Media Info", or "Properties" window of any player app that will open the file, or
    3) Use a general media utility app like "MediaInfo" to read the file characteristics.

  • **how can i make chess to play online?**

    Hi,
    I want to make a web application which is a game of chess. I want to make it in such a way like on yahoo games. Where two people can play chess. I know how to make it possible to play on a single desktop pc. But how can i make it to play online. I need to know about what java technologies I should learn to make this project possible.
    Regards,
    Fahad Ahemd

    ok but how I dont want to create webserver. I mean I can't affort it at this stage of my education. I can afford a webhosting. there are lot of opitons for webhosting are availabe. I can buy one for me. But I want to know what features of java or anything else should be available on that server. 2nd is what do u mean by socket programming. I understand http programming. It includes servlets and jsps. but what is socket programming and why i need it in this project.
    waiting for reply...
    Fahad Ahmed

  • HT5295 How can I stop the auto play feature automatically playing/streaming the next podcast?

    How can I stop the auto play feature automatically playing/streaming the next podcast?

    Hi there.
    I listened to podcast there were two things I found that helped me out. Both we're in the podcast app itself.
    Firstly change the default sorting order. When looking at the list off episodes a available on your ios device tap on the description part at the top, this will bring up the settings for that podcast (subscribe mark as played etc) scroll to the Bottom and select oldest first. This will mean that if you are listening to the latest download it will stop at the end as there will be no more to play.
    Secondly, and useful if listening to older podcasts in the list, you can use the timer to stop once the current episode has ended. To do this when you are in the podcast playback screen slide the "album artwork" up, revealing the playback options and nifty tape playing animation this is where you adjust playback speed and set a timer. The timer has a number of options to set playback to stop after set amount of time. However one of these options is to stop once the current episode you are listening to ends. This can also be current chapter if the podcast you are listening to supports chapters.
    Hope this helps, if not clear let me know

  • TS1717 i rented a movie on iTunes and it stopped with 28 minutes left in the movie  it froze and will not advance.  How can i get it to play.

    i rented a movie on iTunes and it stopped with 28 minutes left in the movie  it froze and will not advance.  How can i get it to play.

    In iTunes select the movie and hit Delete. Follow the prompts and then empty the trash.

  • How can I create a slideshow that depicts only a version of a photo rather than the original? Since the original and new versions are saved together, the aperture slideshow often choices the original rather than the desired version to display/

    How can I create a slideshow that depicts only a version of a photo rather than the original?   Since the original and new versions are saved together, the aperture slideshow often choices the original rather than the desired version to display.

    There are two things we use the name "Slideshow" for in Aperture:  a Slideshow Album, used for making Slideshows, and the Slideshow that is made.  (Imho, it is a design mistake to not call the containers used to create Slideshows, Books, etc., "Albums".)
    The Slideshow will use the Album Pick from any Stack.  A good way to use Aperture is to promote the Image you want to regularly use (such as, for example, a Version with adjustments) to the top of the Stack.  This makes it the Stack Pick, and will be the default Album Pick.  If you haven't done that, you can still change the Album Pick for any Stack in a Slideshow Album.  Expand your Stack(s), select the Image in each Stack that you want to be the Album Pick (and thus shown in the Slideshow), and "Stacks➞Set Album Pick".  (Note the keyboard shortcut; there is also a Toolbar icon for this.)  The change is immediate.  The Slideshow will always show the Album Pick (or, if there is not one, the Stack Pick) for every Stack in your Slideshow Album.

  • HT5622 Hi, can you help me for my payment account? It's always show " Your payment method was declined..." How can I fix it? There's only 3 to choose fpr Visa, Master Card and Amex.. But doesn't have "None".. I can't download any apps from app store :(

    Hi, can you help me for my payment account? It's always show " Your payment method was declined..." How can I fix it? There's only 3 to choose fpr Visa, Master Card and Amex.. But doesn't have "None".. I can't download any apps from app store

    http://support.apple.com/kb/ht1918

Maybe you are looking for