all groups > flash (macromedia) > october 2007 >
You're in the

flash (macromedia)

group:

action script 3 and adding code to buttons


Re: action script 3 and adding code to buttons DMennenoh **AdobeCommunityExpert**
10/12/2007 6:35:58 PM
flash (macromedia):
You cannot put code on objects in AS3 - code goes in the timeline, which is
the proper way, even in AS2. However, you can use AS2, until you learn the
proper way.

--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/

action script 3 and adding code to buttons dustycoats
10/12/2007 10:11:50 PM
When I open a new doc and selct action script 3 it won't allow me to insert
code by selcting the button on the stage. It does if I select action script 2.
All my old pages update ok but if I make new buttons it wont take the code.
CAn someone tell me what is going on???


Thanks a lot
Re: action script 3 and adding code to buttons dustycoats
10/13/2007 1:25:11 AM
Thanks for the reply,

I tried putting the code in the timeline keyframe and it still did not work.
I am in a pinch because my whole graphics arts class (two of them) have built
their pages and now the old code I used does not work as it did in our schools
older version. Can you please tell where to insert the load movie code? thanks

This is what I am trying to get the buttons to do.

on(press){
_root.loadMovie("graphic_arts/graphic_arts.swf");

}
Re: action script 3 and adding code to buttons clbeech
10/13/2007 1:58:51 AM
If your in a bind at the moment, I would suggest not attempting to learn AS3.
The system is very different, good, but different, the syntax structure is much
more strict and most things have been revised to use a listener/broadcaster (or
event dispatcher) model, as well as most coding being class oriented,
additionally the graphic display structure is quite different.

Now did you change your publish settings back to AS2? If so, you should still
be able to apply the above code to a button instance. However, as Dave stated,
even in AS2 the code is best used from the timeline, to do so with the code
above (which the on handler here is meant for Object attachment) you need to
write it like this:

my_btn.onPress = function() {
_root.loadMovie("graphic_arts/graphic_arts.swf");
}

I would also consider using a MovieClipLoader and the loadClip method
forloading swf files, as it gives you more control over the load targeting,
progress reporting, and event notifications.

All this said, to use a button and load a file in AS3, you need to add an
event listener to the button instance and construct a responding function to
the event, in this case the loading of a swf file. Additionally, in AS3 the
MovieClipLoader class, as well as the loadMovie methods have been replaced by
the Loader classes and must be used to load swf files. So construct a button
in AS3 you must write something like the following:


import flash.display.*;
import flash.net.URLRequest;

function loadSWF(event:MouseEvent) {
var ldr:Loader = new Loader();
var url:String = 'graphic_arts/graphic_arts.swf';
var file:URLRequest = new URLRequest(url);
ldr.load(file);
addChild(ldr);
}
my_btn.addEventListener(MouseEvent.CLICK, loadSWF);
AddThis Social Bookmark Button