GPS.ane for my app and i keep getting an error Line 55, Column 50 1120: Access of undefined property onClickStop - actionscript

**trying to use the GPS.ane for my app and I keep getting an error
"Line 55, Column 50 1120: Access of undefined property onClickStop."
this is the line that is giving me the headache I think I am missing something small but i cant find it. The app is as you will think gives out the latitude and longitude of where you are at. thank you for you help **
**package {
import com.myflashlab.air.extensions.gps.Gps;
import com.myflashlab.air.extensions.gps.LocationAccuracy;
import com.myflashlab.air.extensions.gps.Location;
import com.myflashlab.air.extensions.gps.GpsEvent;
import com.myflashlab.air.extensions.nativePermissions.PermissionCheck;
import flash.utils.setTimeout;
import com.myflashlab.air.extensions.dependency.OverrideAir;
import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.StatusEvent;
import flash.events.InvokeEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TouchEvent;
import flash.filesystem.File;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.ui.Keyboard;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
public class Main extends MovieClip{
private var _exPermissions:PermissionCheck = new PermissionCheck();
public function Main() {
// constructor code
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate);
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate);
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys);
stage.scaleMode = StageScaleMode.EXACT_FIT;
stage.align = StageAlign.TOP_LEFT;
startBtn.addEventListener(TouchEvent.TOUCH_TAP, onClickStart);
stopBtn.addEventListener(TouchEvent.TOUCH_TAP, onClickStop);
checkPermissions();
}
private function onInvoke(e:InvokeEvent):void
{
NativeApplication.nativeApplication.removeEventListener(InvokeEvent.INVOKE, onInvoke);
}
private function handleActivate(e:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
private function handleDeactivate(e:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
}
private function handleKeys(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.BACK)
{
e.preventDefault();
NativeApplication.nativeApplication.exit();
}
}
private function checkPermissions():void
{
// first you need to make sure you have access to the Location API
var permissionState:int;
if(_exPermissions.os == PermissionCheck.ANDROID)
{
permissionState = _exPermissions.check(PermissionCheck.SOURCE_LOCATION);
}
else if(_exPermissions.os == PermissionCheck.IOS)
{
permissionState = _exPermissions.check(PermissionCheck.SOURCE_LOCATION_WHEN_IN_USE);
}
if (permissionState == PermissionCheck.PERMISSION_UNKNOWN || permissionState == PermissionCheck.PERMISSION_DENIED)
{
if(_exPermissions.os == PermissionCheck.ANDROID)
{
_exPermissions.request(PermissionCheck.SOURCE_LOCATION, onRequestResult);
}
else if(_exPermissions.os == PermissionCheck.IOS)
{
_exPermissions.request(PermissionCheck.SOURCE_LOCATION_WHEN_IN_USE, onRequestResult);
}
}
else
{
textDisplay.appendText("permissions are already ok, you can use gps features."+ "\n");
init();
}
function onRequestResult($state:int):void
{
if ($state != PermissionCheck.PERMISSION_GRANTED)
{
textDisplay.appendText("You did not allow the app the required permissions!"+ "\n");
}
else
{
textDisplay.appendText("necessary permissions are now granted."+ "\n");
init();
}
}
}
public function onClickStart (evt:TouchEvent):void{
textDisplay.appendText("Location Uptade Started.\n");
// use the start method to get gps information periodically (the gps icon will be shown at your device status bar)
Gps.location.addEventListener(GpsEvent.LOCATION_UPDATE, onLocationUpdate);
Gps.location.start(LocationAccuracy.HIGH, 0, 5000);
startBtn.alpha = 0.5;
stopBtn.alpha = 1;
}
public function onClickstop (evt:TouchEvent):void{
textDisplay.appendText("Location Uptade Stopped.\n");
// simply stop the gps service when you don't need to get location information periodically anymore.
Gps.location.removeEventListener(GpsEvent.LOCATION_UPDATE, onLocationUpdate);
Gps.location.stop();
startBtn.alpha = 1;
stopBtn.alpha = 0.5;
}
function onLocationUpdate(e:GpsEvent):void
{
textDisplay.appendText(" ------------------------------- onLocationUpdate"+ "\n");
var loc:Location = e.param;
textDisplay.appendText("accuracy = " + loc.accuracy+ "\n");
textDisplay.appendText("altitude = " + loc.altitude+ "\n");
textDisplay.appendText("bearing = " + loc.bearing+ "\n");
textDisplay.appendText("latitude = " + loc.latitude+ "\n");
textDisplay.appendText("longitude = " + loc.longitude+ "\n");
textDisplay.appendText("provider = " + loc.provider+ "\n");
textDisplay.appendText("speed = " + loc.speed+ "\n");
textDisplay.appendText("time = " + loc.time+ "\n");
textDisplay.appendText("---------------------------------"+ "\n");
}
private function myDebuggerDelegate($ane:String, $class:String, $msg:String):void
{
textDisplay.appendText($ane+"("+$class+") "+$msg+ "\n");
}
private function init():void
{
// remove this line in production build or pass null as the delegate
OverrideAir.enableDebugger(myDebuggerDelegate);
Gps.init(); // call init only once in your project
// will return null if no known last location has been found
Gps.location.getLastLocation(onLocationResult);
// may take a while depending on when gps info is found
Gps.location.getCurrentLocation(onLocationResult);
function onLocationResult($result:Location):void
{
if (!$result)
{
textDisplay.appendText("location is null"+ "\n");
return;
}
textDisplay.appendText("accuracy = " + $result.accuracy+ "\n");
textDisplay.appendText("altitude = " + $result.altitude+ "\n");
textDisplay.appendText("bearing = " + $result.bearing+ "\n");
textDisplay.appendText("latitude = " + $result.latitude+ "\n");
textDisplay.appendText("longitude = " + $result.longitude+ "\n");
textDisplay.appendText("provider = " + $result.provider+ "\n");
textDisplay.appendText("speed = " + $result.speed+ "\n");
textDisplay.appendText("time = " + $result.time+ "\n");
textDisplay.appendText("---------------------------------"+ "\n");
}
}
}
}
**

stopBtn.addEventListener(TouchEvent.TOUCH_TAP, onClickStop);
public function onClickstop (evt:TouchEvent):void{
Your function has a low case s in stop, but when you refer to it you use a capital S.
Think that's all that's wrong

Related

Get view count using Google Youtube API

I want to get the view count of set of videos. Following is the relevant part of my code.
SearchResult singleVideo = iteratorSearchResults.next();
ResourceId rId = singleVideo.getId();
// Double checks the kind is video.
if (rId.getKind().equals("youtube#video")) {
Thumbnail thumbnail = singleVideo.getSnippet().getThumbnails().get("default");
System.out.println(" Video Id" + rId.getVideoId());
System.out.println(" Title: " + singleVideo.getSnippet().getTitle());
System.out.println(" Thumbnail: " + thumbnail.getUrl());
YouTube.Videos.List list = youtube.videos().list("statistics");
list.setId(rId.getVideoId());
list.setKey("youtube.apikey");
Video v = list.execute().getItems().get(0);
System.out.println("The view count is: "+v.getStatistics().getViewCount());
System.out.println("\n-------------------------------------------------------------\n");
}
This gives the following error in the line "YouTube.Videos.Lists list = youtube.videos().list("statistics");".
error: method list in class YouTube.Videos cannot be applied to given types;
If this is a compilation error then there might be some issue with the library version that you have included. I tried sample code from youtube API docs and it worked for me.
I have removed some extra code from the sample to show how view counts can be retrieved for a single video:
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.services.samples.youtube.cmdline.Auth;
import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.model.Video;
import com.google.api.services.youtube.model.VideoListResponse;
import java.io.IOException;
import java.math.BigInteger;
public class GeolocationSearch {
public static void main(String[] args) {
try {
YouTube youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
#Override
public void initialize(HttpRequest request) throws IOException {
}
}).setApplicationName("APP_ID").build();
String apiKey = "API_KEY";
YouTube.Videos.List listVideosRequest = youtube.videos().list("statistics");
listVideosRequest.setId("lf_wVfwpfp8"); // add list of video IDs here
listVideosRequest.setKey(apiKey);
VideoListResponse listResponse = listVideosRequest.execute();
Video video = listResponse.getItems().get(0);
BigInteger viewCount = video.getStatistics().getViewCount();
System.out.println(" ViewCount: " + viewCount);
System.out.println("\n-------------------------------------------------------------\n");
} catch (GoogleJsonResponseException e) {
System.err.println("There was a service error: " + e.getDetails().getCode() + " : "
+ e.getDetails().getMessage());
} catch (IOException e) {
System.err.println("There was an IO error: " + e.getCause() + " : " + e.getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
}
}

jenkins cli with checkout Subversion using groovy script

Is there a way to check out any Subversion project using Jenkins-Cli by executing a groovy script on the master? I can get to the point of creating SVN client manager[org.tmatesoft.svn.core.wc.SVNClientManager], but can't really understand how to employ that in checking out an SVN project from the URL.
After a lot of hit and trials I have come up with this, might be useful for someone else:
import jenkins.*;
import jenkins.model.*;
import hudson.*;
import hudson.model.*;
import hudson.slaves.SlaveComputer;
import hudson.scm.SubversionSCM;
import hudson.remoting.Channel;
import hudson.FilePath;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationProvider;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.ISVNDirEntryHandler;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import java.lang.*;
import java.util.ArrayList;
import java.util.List;
private boolean checkNodeExist(String node_Name){
if (Jenkins.getInstance().slaves.find({it.name == node_Name}) == null)
return false;
else
return true;
}
private ISVNAuthenticationProvider createAuthenticationProvider(AbstractProject context) {
return Jenkins.getInstance().getDescriptorByType(SubversionSCM.DescriptorImpl.class)
.createAuthenticationProvider(context);
}
public class SimpleSVNDirEntryHandler implements ISVNDirEntryHandler {
private final List<SVNDirEntry> dirs = new ArrayList<SVNDirEntry>();
public List<String> getDirs() {
List<String> sortedDirs = new ArrayList<String>();
for (SVNDirEntry dirEntry : dirs) {
sortedDirs.add(dirEntry.getName());
}
return sortedDirs;
}
public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
dirs.add(dirEntry);
}
}
public void PerfromSVNListOperationOnMaster(SVNURL svnUrl){
try{
SVNRepository repo = SVNRepositoryFactory.create(svnUrl);
SVNClientManager clientManager = SubversionSCM.createSvnClientManager(createAuthenticationProvider())
SVNLogClient logClient = clientManager.getLogClient();
SimpleSVNDirEntryHandler dirEntryHandler = new SimpleSVNDirEntryHandler();
List<String> dirs = new ArrayList<String>();
logClient.doList(repo.getLocation(),SVNRevision.HEAD, SVNRevision.HEAD,false,SVNDepth.INFINITY,SVNDirEntry.DIRENT_KIND,dirEntryHandler)
dirs = dirEntryHandler.getDirs();
println (dirs)
}
catch(SVNException svnEx){
println "#Error: " + svnEx;
throw svnEx
}
}
public void PerfromSVNCheckOutOperation(SVNURL svnUrl,boolean isMaster,String appender,SlaveComputer computer = null){
try{
SVNRepository repo = SVNRepositoryFactory.create(svnUrl);
SVNClientManager clientManager = SubversionSCM.createSvnClientManager(createAuthenticationProvider());
SVNUpdateClient updateClient = clientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
String destDir = svnUrl.getPath().substring(svnUrl.getPath().lastIndexOf('/')+1);
if (isMaster == true){
updateClient.doCheckout(repo.getLocation(),new java.io.File(System.getProperty("java.io.tmpdir"),destDir + '_' + appender),SVNRevision.HEAD,SVNRevision.HEAD,SVNDepth.INFINITY,false);
}else{
if (computer == null){
throw new IllegalArgumentException("#Error: Argument:computer can't be null when we need to checkout in slave");
}else{
updateClient.doCheckout(repo.getLocation(),new java.io.File(System.getProperty("java.io.tmpdir"),destDir + '_' + appender),SVNRevision.HEAD,SVNRevision.HEAD,SVNDepth.INFINITY,false);
Channel slaveChannel = computer.getChannel();
FilePath fpSrc = new hudson.FilePath(new java.io.File(System.getProperty("java.io.tmpdir"),destDir + '_' + appender));
//println new java.io.File((slave.getWorkspaceRoot().toString()),destDir).toString().replace('\\','/')
FilePath fpDestination = new hudson.FilePath(slaveChannel,new java.io.File((slave.getWorkspaceRoot().toString()),destDir + '_' + appender).toString().replace('\\','/'));
println "Copying files recursively from Temp directory in master to slave";
int files_copied = fpSrc.copyRecursiveTo(fpDestination);
println files_copied
fpSrc.deleteRecursive();
}
}
}
catch (Exception ex){
throw new Exception("#Error:",ex);
}
}
if (args.length == 4){
String url = new String(args[0]);
SVNURL svn_url = null;
try{
svn_url = SVNURL.parseURIDecoded(url);
}
catch(SVNException svnEX){
println "#Error: Check SVN repository Location.";
throw svnEX;
}
String nodeName = new String(args[1]);
String operation = new String(args[2]);
String checkoutAppendString = new String(args[3]);
println args
if (nodeName.equalsIgnoreCase("master")){
println "Executing script on master"
if (operation.equalsIgnoreCase("list")){
PerfromSVNListOperationOnMaster(svn_url);
}else{
PerfromSVNCheckOutOperation(svn_url,true,checkoutAppendString);
}
}else{
if (checkNodeExist(nodeName)){
slave = Jenkins.getInstance().slaves.find({it.name == nodeName});
SlaveComputer computer = slave.getComputer();
if (computer.isOffline()){
println "#Error: $slave is offline."
return
}else{
if (operation.equalsIgnoreCase("list")){
PerfromSVNListOperationOnMaster(svn_url)
}else{
PerfromSVNCheckOutOperation(svn_url,false,checkoutAppendString,computer);
}
}
}else{
println "#Error: $nodeName not found."
return
}
}
}else{
println "Invalid Usage, expecting 3 arguments : 1.RepositoryURL 2.NodeName 3.OperationType"
return
}

Getting User Tweets into Processing successfully - Twitter4j

Managed to finally get my own tweets into Processing, using the following code and the twitter4j library. I've now been trying to adapt the code to pull in the tweets of a specific user, without any luck, regardless of the many people online who have posted 'working code'. Could someone steer me right and show me what exactly needs to be altered? Thanks!
import twitter4j.util.*;
import twitter4j.*;
import twitter4j.management.*;
import twitter4j.api.*;
import twitter4j.conf.*;
import twitter4j.json.*;
import twitter4j.auth.*;
import java.util.*;
List<Status>statuses = null;
TwitterFactory twitterFactory;
Twitter twitter;
void setup() {
size(100, 100);
background(0);
connectTwitter();
getTimeline();
}
void draw() {
background(0);
}
// Initial connection
void connectTwitter() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("XXXX");
cb.setOAuthConsumerSecret("XXXX");
cb.setOAuthAccessToken("XXXX");
cb.setOAuthAccessTokenSecret("XXXX");
twitterFactory = new TwitterFactory(cb.build());
twitter = twitterFactory.getInstance();
println("connected");
}
// Get your tweets
void getTimeline() {
try {
statuses = twitter.getUserTimeline();
}
catch(TwitterException e) {
println("Get timeline: " + e + " Status code: " + e.getStatusCode());
}
for (Status status:statuses) {
println(status.getUser().getName() + ": " + status.getText());
}
}
EDIT - Amended code to get User Tweets. Produces no errors or results...
void getUserTimeLine(long stephenfry) {
try {
ResponseList<Status> statuses = twitter.getUserTimeline(stephenfry);
}
catch(TwitterException e) {
println("Get timeline: " + e + " Status code: " + e.getStatusCode());
}
for (Status status : statuses) {
System.out.println(status.getText());
}
}
You just need to add following to your code to retrieve any users timeline-
void getUserTimeLine(long userID/*You can also use screenName*/) {
ResponseList<Status> statuses = twitter.getUserTimeline(userID/*You can also use screenName*/);
for (Status status : statuses) {
System.out.println(status.getText());
}
}

Actionscript compiler MTASC and Events

Please help, how to make netEvent work in a compiled flash, for instance I can't even make macromedia example to work:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.onMetaData = function(infoObject:Object) {
for (var propName:String in infoObject) {
trace(propName + " = " + infoObject[propName]);
}
};
ns.play("http://www.helpexamples.com/flash/video/water.flv");
It must return metainfo, but seems like no event is called at all.
What am I doing wrong?
Thanks!
This is right from Adobe docs:
package {
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
public class NetConnectionExample extends Sprite {
private var videoURL:String = "Video.flv";
private var connection:NetConnection;
private var stream:NetStream;
public function NetConnectionExample() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(null);
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + videoURL);
break;
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function connectStream():void {
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.client = new CustomClient();
var video:Video = new Video();
video.attachNetStream(stream);
stream.play(videoURL);
addChild(video);
}
}
}
class CustomClient {
public function onMetaData(info:Object):void {
trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void {
trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}
Looks to me like you're missing quite a bit in the code that you posted and you won't get what you're looking for by missing required setup code.

Adobe Air how to check if URL is online\gives any response exists?

I have url I want to check if it is live. I want to get bool value. How to do such thing?
You can use an URLLoader and listen for the events to check if it loads, and if not what might be the problem. Would be handy to use the AIRMonitor first to make sure the client's computer is online in the first place.
Here is a class I started to write to illustrate the idea:
package
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.HTTPStatusEvent;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
/**
* ...
* #author George Profenza
*/
public class URLChecker extends EventDispatcher
{
private var _url:String;
private var _request:URLRequest;
private var _loader:URLLoader;
private var _isLive:Boolean;
private var _liveStatuses:Array;
private var _completeEvent:Event;
private var _dispatched:Boolean;
private var _log:String = '';
public function URLChecker(target:IEventDispatcher = null)
{
super(target);
init();
}
private function init():void
{
_loader = new URLLoader();
_loader.addEventListener(Event.COMPLETE, _completeHandler);
_loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, _httpStatusHandler);
_loader.addEventListener(IOErrorEvent.IO_ERROR, _ioErrorEventHandler);
_loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, _securityErrorHandler);
_completeEvent = new Event(Event.COMPLETE, false, true);
_liveStatuses = [];//add other acceptable http statuses here
}
public function check(url:String = 'http://stackoverflow.com'):void {
_dispatched = false;
_url = url;
_request = new URLRequest(url);
_loader.load(_request);
_log += 'load for ' + _url + ' started : ' + new Date() + '\n';
}
private function _completeHandler(e:Event):void
{
_log += e.toString() + ' at ' + new Date();
_isLive = true;
if (!_dispatched) {
dispatchEvent(_completeEvent);
_dispatched = true;
}
}
private function _httpStatusHandler(e:HTTPStatusEvent):void
{
/* comment this in when you're sure what statuses you're after
var statusesLen:int = _liveStatuses.length;
for (var i:int = statusesLen; i > 0; i--) {
if (e.status == _liveStatuses[i]) {
_isLive = true;
dispatchEvent(_completeEvent);
}
}
*/
//200 range
_log += e.toString() + ' at ' + new Date();
if (e.status >= 200 && e.status < 300) _isLive = true;
else _isLive = false;
if (!_dispatched) {
dispatchEvent(_completeEvent);
_dispatched = true;
}
}
private function _ioErrorEventHandler(e:IOErrorEvent):void
{
_log += e.toString() + ' at ' + new Date();
_isLive = false;
if (!_dispatched) {
dispatchEvent(_completeEvent);
_dispatched = true;
}
}
private function _securityErrorHandler(e:SecurityErrorEvent):void
{
_log += e.toString() + ' at ' + new Date();
_isLive = false;
if (!_dispatched) {
dispatchEvent(_completeEvent);
_dispatched = true;
}
}
public function get isLive():Boolean { return _isLive; }
public function get log():String { return _log; }
}
}
and here's a basic usage example:
var urlChecker:URLChecker = new URLChecker();
urlChecker.addEventListener(Event.COMPLETE, urlChecked);
urlChecker.check('wrong_place.url');
function urlChecked(event:Event):void {
trace('is Live: ' + event.target.isLive);
trace('log: ' + event.target.log);
}
The idea is simple:
1. You create a checked
2. Listen for the COMPLETE event(triggered when it has a result
3. In the handler check if it's live and what it logged.
In the HTTP specs, 200 area seems ok, but depending on what you load, you might need
to adjust the class. Also you need to handle security/cross domain issue better, but at least it's a start.
HTH
An important consideration that George's answer left out is the URLRequestMethod. If one were trying to verify the existence of rather large files (e.g, media files) and not just a webpage, you'd want to make sure to set the method property on the URLRequest to URLRequestMethod.HEAD.
As stated in the HTTP1.1 Protocol:
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.
Hence, if you really only want to verify the existence of the URL, this is the way to go.
For those who need the code spelled out:
var _request:URLRequest = URLRequest(url);
_request.method = URLRequestMethod.HEAD; // bandwidth :)
Otherwise, George's answer is a good reference point.
NB: This particular URLRequestMethod is only available in AIR.

Resources