-
AS3 makes me cry
Ok, I've recently started to learn AS3 and I'm found out very quickly that it's a completely new ball game. :yikes: Arrrrrrrghhhhhh Understatement
Can anyone help advance my learning a little in regards to this problem?
I have a few buttons on my main.swf which i want to use to load external movies. The problem I am having is that in AS2 I could just attach the AS to the button, but it seems in AS3 this is not the case?
How can I reference the specific buttons and from the AS? Considering that I am using 1 piece of code slightly modified for each button.
Code:
var imageRequest:URLRequest = new URLRequest("movie2.swf");
car imageLoader:Loader = new Loader();
imageLoader.load(imageRequest);
addChild(imageLoader);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
event.target.content.slidingpages.x -= 100;
}
Any help would be great as I'm at a complete loss on this. Thanks in Advance
-
If I understand you correctly, you are just having problems making your buttons work?
Lets say a button is on the stage called 'about_btn' - it will load the about page
in the actions panel for that frame your code would look like this
import flash.events.MouseEvent;
about_btn.addEventListener(MouseEvent.CLICK, aboutButtonClicked);
function aboutButtonClicked (e:MouseEvent):void {
trace("about button was clicked");
}
first we import the MouseEvent, we must do this so the flash player knows what a MouseEvent is.
Next, we add an event listener to the about_btn. Notice referencing the items on the stage is exactly like AS2: stage.child.anotherchild
After the type of event we listen for we tell it the function to call.
In this function you can set the url for the swf to load, and load the file.
you will probably need a loader for each page...
Hope that helps
-
A simple way is to place your Loader objects in MovieClips. Since MCs are dynamic you can add variables like this:
mc.myURL="movie.swf";
You get reference over
var mcNew:MovieClip = event.currentTarget.content.parent.parent as MovieClip;
trace(mcNew.myURL);
-
Thanks for everything folks, got this sorted now a few headaches later.