I’m using Flash Pro. CS5 with ActionScript 3, and I’ve never worked with flash before, and I’ve searched for a while for the way to do this and I continuously get syntax errors with this code. I saw someone asked a similar question, and a person said the code was deprecated, so I can only assume since mine looks very similar that its also deprecated. From flash I’m trying to make a button that will open a PDF file. The code I have right now is;
on(release){
getURL("Index Dividers.pdf");
}
and my syntax error keeps saying ‘expecting semicolon before left brace’ Stupid as it may sound, I added a semicolon before the left brace, and then one error turned into 3 errors, so that didnt solve anything. So does anyone know the proper code to open a PDF file? It will be greatly appreciated!
getURLhas been replaced withnavigateToURL, which works by accepting aURLRequestobject. In your case, it looks like this:As for the click handler, you can’t you the
on(ACTION)notation anymore, everything is event based now. You need to set up a listener on your target, and assign a handler function to be called when the event fires:A bit more about events:
Firstly, an event. An event can be thought of as a message that an object broadcasts when an action has occurred. The one we’re using here is
MouseEvent.CLICK. This actually resolves to the string ‘onClick’, that is stored in the MouseEvent class, but don’t worry about those details for now. An object will broadcast this event when the user clicks it with their mouse. Other mouse events includeMouseEvent.MOUSE_OVERandMouseEvent.MOUSE_OUT. There are other events for all kinds of things, and you can even create your own.Now listeners. In order to know when an event has been dispatched by an object, you add a listener to that object. Using the example from above, we’ll break it down:
this.addEventListener– we’re saying that we want to listen for an event coming from the targeted object. You have changed this in your code to target a button instance, which is perfect.(MouseEvent.CLICK,– this is the event you want to listen for.clickHandler);– this is the function that will be called as a result of the event being detected.So now all you need is the function that we’ve named as the handler (the second parameter to
addEventListener. This function must accept one argument, an event object. This is a reference to the actual instance of the event that was dispatched, and so for a mouse event it will be typecast asMouseEvent. In the above example we didn’t have any use for this object, but you must still have it in the function declaration or Flash will not compile.