I have a slideshow that is fading through and each Slide links to a different page. Have a simple text rollover effect I activate with AS3 so when the slide is rolled over the text changes color.
I can get it to work with just one slide but I can't get it to work when I add 3 more slides
inv_btn.addEventListener(MouseEvent.CLICK, buttonHandler);
inv_btn.addEventListener(MouseEvent.MOUSE_OVER, rollOver);
inv_btn.addEventListener(MouseEvent.ROLL_OUT, rollOut);
function buttonHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.hautepets.net/pages/grooming.php"));
}
function rollOver(event:MouseEvent):void {
rollText_1.gotoAndPlay("over");
}
function rollOut(event:MouseEvent):void {
rollText_1.gotoAndPlay("out");
}
Then add the code 3 more times but change instance names and also move the button for the next slide to another key frame. Not sure this is necessary but I also tried it with out doing this.
I use the exact same code I just change instance names on the new slide and in the code like so:
inv_btn2.addEventListener(MouseEvent.CLICK, buttonHandler2);
inv_btn2.addEventListener(MouseEvent.MOUSE_OVER, rollOver2);
inv_btn2.addEventListener(MouseEvent.ROLL_OUT, rollOut2);
function buttonHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.hautepets.net"));
}
function rollOver2(event:MouseEvent):void {
rollText_2.gotoAndPlay("over");
}
function rollOut2(event:MouseEvent):void {
rollText_2.gotoAndPlay("out");
}
any ideas of what I am doing wrong?
you need to declare these instances in the first frame, even if you don't use them
just put inv_btn2 and rollText_2 also to first frame, it will solve the problem and use visible = false/true; to show/hide them on different frames or you also can put them out of stage on first frame.
Related
I`m trying to build a simple game where you will view a map with 5 clickable objects.
When you click these objects you can navigate trough some pages and upon clicking the last button it returns to the map itself. Now everything is working as it should. Upon clicking this specific last button It has the following code.
jamenext2.addEventListener(MouseEvent.MOUSE_DOWN, gotomap2);
function gotomap2(event:MouseEvent):void {
gotoAndPlay("map2");
}
What I would like to have now is to have a bar on the Map itself, and when you have reached the button that has the above code attached, the bar increments by 20%, and so the same for the 4 other clickable buttons on the map. Upon 100% completion I would like it to play the next animation further on in the timeline.
I have tried the following, but I am not that good in writing code, and I`m not very sure where to place it exactly.
var total1 = 100;
_root.loaded1 = 0;
while(true) {
this.scaleX = _root.loaded1/total1;
}
_root.loaded1 = _root.loaded1 + 20;
gotoAndPlay("map2");
I have no idea on how to do this.
What your going to want to do is create a square or bitmap class for the progress bar. From there, create a square with a MouseEvent.MOUSE_DOWN for the buttons.
There is different ways of doing this. Judging from your sample code your using the timeline for scenes so you might want to put a button in there to scale in each scene.
You could size it at twenty percent and make it fully transparent and become viable on the first click. Then increment by twenty percent until a hundred percent visible. You could then also have another button that would roll back a page.
Mostly pseudo code but something like this:
(Example Reference link: http://www.actionscript.org/resources/articles/792/1/Drawing-Shapes-with-AS3/Page1.html )
import flash.display.Shape;
private var square:Shape;
main_method
{
square = new Shape();
//draw shape
square.graphics.beginFill(0x1111FF, 1);
square.graphics.drawRect(30, 30, 200, 200);
square.graphics.endFill();
square.alpha = .5;
addChild(square);
}
//somewhere in a MouseEvent.MOUSE_DOWN class
{
gotoAndPlay("map1");
}
}
It's also possible rather than creating a square in code to create a symbol instance name on the stage and and in the properties tab give it a name and reference it in code.
I'm trying to code the navigation of a Flash AS3 project in an actionscript file. In the project there are several frames with buttons to navigate through the project. The ones I have coded for the first frame work, but on any other frame they don't.
here is the code:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
public function Main()
{
trace("it's working");
btn_one.addEventListener(MouseEvent.MOUSE_UP,eventResponse1);
btn_two.addEventListener(MouseEvent.MOUSE_UP,eventResponse2);
btn_three.addEventListener(MouseEvent.MOUSE_UP,eventResponse3);
btn_four.addEventListener(MouseEvent.MOUSE_UP,eventResponse4);
btn_five.addEventListener(MouseEvent.MOUSE_UP,eventResponse5);
btn_six.addEventListener(MouseEvent.MOUSE_UP,eventResponse6);
}
function eventResponse1(evt:MouseEvent):void
{
gotoAndStop("game");
}
function eventResponse2(evt:MouseEvent):void
{
gotoAndStop("specimenroom");
}
function eventResponse3(evt:MouseEvent):void
{
gotoAndStop("how");
}
function eventResponse4(evt:MouseEvent):void
{
gotoAndStop("game");
}
function eventResponse5(evt:MouseEvent):void
{
gotoAndStop("feedback");
}
function eventResponse6(evt:MouseEvent):void
{
gotoAndStop("home");
}
}
}
In the code the first five buttons work, but the sixth doesn't. This button is not located on the first frame of the main timeline, it's on the second and third frame. It doesn't work at all. What code is needed to get them to work? Any help is much appreciated, thank you.
The button must be present on the frame that the AS3 code gets executed on.
For example, if your button is on frame 2 and your code that tries to add the listener is on frame 1, that will not work.
I assume you are using a Document class, so the same applies. Only what is present on the stage at the time that constructor code runs, is available for you to work with.
What you could do is have a method that adds listeners to the appropriate buttons when you go to that frame.
There are other solutions that would require a more radical change to your current design of using the timeline to change screens, so I suggested the one that would require minimum change.
Because you asked in comments another possible solution is to not navigate through your different screens via timeline frames, but instead do it via code and MovieClip symbols that contain your UI screens. You would just create the instances of the screens in code as needed and handle their handlers appropriately when doing so.
other solution is that make button accessible on first frame and change its alpha to zero so that its not visible. This why u will not have to change the code and just change the time line.
I am new to as3. I create a rectangle and convert it to symbol. Then I go into the symbol and create two sliders. Also, I make the symbol draggable.
controlPanel_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStartF);
controlPanel_mc.addEventListener(MouseEvent.MOUSE_UP, dragEndF);
function dragStartF(e:MouseEvent){
e.currentTarget.startDrag();
}
function dragEndF(e:MouseEvent){
e.currentTarget.stopDrag();
}
It works fine, but I can't use the slider. If I drag the slider, the entire movie clip moved. How can I solve this problem? Cheers!
Without more info on the structure of your FLA-file I assume that controlPanel_mc is the container containing the rectangle[background] and the two sliders.
What it seems like you did in your code was to add event listener to the container, what that means is that "if a click occures anywhere on this object, do the following". Since that clip "owns" the 2 sliders, the sliders will not get any MOUSE_DOWN-events since the parent is always the one handling the event first.
You probably want to convert the background into a symbol and add the eventListeners to that object instead.
bg.addEventListener(MouseEvent.MOUSE_DOWN, onBgClick);
bg.addEventListener(MouseEvent.MOUSE_UP, onBgRelease);
function onBgClick(e:MouseEvent){
controlPanel_mc.startDrag();
}
function onBgRelease(e:MouseEvent){
controlPanel_mc.stopDrag();
}
That should solve your issue :)
I'm creating a website in flash and I'm having trouble finding what code to use for timeline and movieclip navigation. Right now I have my main navigation buttons on the main timeline, and a separate animation that serves as my content container on a movieclip within the main timeline. I don't know how to make it so that when I click a button on the main timeline to have it navigate to a frame within the content movieclip. I've found many troubleshooters regarding how to control the main timeline from within a movieclip, which is the opposite of what I'm trying to do.
I also have MouseOut handlers on the buttons which direct to mouse out animations on the main timeline.
HomeBtn1.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_1);
Num2Btn.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_2);
ThrdBtn1.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_3);
function fl_MouseOutHandler_1(event:MouseEvent):void
{
gotoAndPlay(2);
trace("Moused out");
}
function fl_MouseOutHandler_2(event:MouseEvent):void
{
gotoAndPlay(30);
trace("Moused out");
}
function fl_MouseOutHandler_3(event:MouseEvent):void
{
gotoAndPlay(56);
trace("Moused out");
}
I would like it if I could add a function like this:
function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
gotoAndStop(x);
}
But with a path targeted within the movieclip, I know it may sound like a simple question but I'm relatively new to flash.
To target the content movieclip:
1. Give it an instance name.
Select it on the stage and enter a name in the textfield on the Properties panel. Call it something like 'contentClip'.
2. Access it in your code using the instance name.
contentClip.gotoAndStop(30);
Will make the content clip go to frame 30.
i have tried to research this issue, but being a flash newbie i struggle to wade through the terminology...
i am using the piecemaker 2 slider on the landing page of my BudeStrings Dev Site. the slider contains a total of 5 slides; the first is a movie clip containing multiple frames and the following four are animated text clips consisting of only one frame each.
as per instructions i found on the interwebs, i added a keyframe after last frame of the first (multiframe) clip and added the following code:
dispatchEvent(new Event(Event.COMPLETE));
stop();
to stop the clip looping and to enable the autoplay behaviour of the slider. this works absolutely fine with the first (multiframe) movie clip, but when i try to add the same code to the other four (single frame) clips it does not have the desired effect.
these four clips use the following code:
var myString:String = "Sample text "
var myArray:Array = myString.split("");
addEventListener(Event.ENTER_FRAME, frameLooper);
function frameLooper(event:Event):void {
if (myArray.length > 0){
TextField.appendText(myArray.shift());
}
else {
removeEventListener(Event.ENTER_FRAME, frameLooper);
}
}
to display some text with an animated typing effect. if i add a keyframe with the dispatchEvent code as i did on the first clip it stops working and when i append the dispatchEvent code to the above actionscript it has no effect, and piecemaker 2 stops autoplaying when it hits slide number 2.
beyond that i have no idea what is causing the problem. please help.
regards, jan
First of all, you should use the appendText method on a textfield instance, not the class itself (the compiler should give you an error). So if the textfield on your stage is called 'txt' it would become 'txt.appendText..'. Secondly, you should define the event dispatching within the else section as at the time it runs, your animation would be completed.
[edit] make sure you enable strict mode in your publish settings