Scrolling within AS3 Flash - actionscript-3

I'm trying to scroll a movieclip within flash. The problem is I have buttons within the movieClip so everytime I try to scroll its difficult not to open the button. My code is below for the scroll im using which is fairly simple.
ChestBiceps.addEventListener(MouseEvent.MOUSE_DOWN, ClipDraggedOn);
var boundsRect:Rectangle = new Rectangle(ChestBiceps.x, -200, 0, 310);
function ClipDraggedOn(event:MouseEvent):void {
ChestBiceps.startDrag(false, boundsRect);
stage.addEventListener(MouseEvent.MOUSE_UP, ClipDraggedOff);
}
function ClipDraggedOff(event:MouseEvent):void {
ChestBiceps.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, ClipDraggedOff); }
Could someone try and figure how I disable the buttons almost whilst scrolling? I still want to be able to use the buttons, just not when scrolling...Thanks in advance

To disable the buttons add the following:
function ClipDraggedOn(event:MouseEvent):void {
ChestBiceps.mouseEnabled = false;
ChestBiceps.mouseChildren = false;
[...]
To re-enable the buttons add the following:
function ClipDraggedOff(event:MouseEvent):void {
ChestBiceps.mouseEnabled = true;
ChestBiceps.mouseChildren = true;
[...]

Related

How can I make a symbol appear after clicking in two different buttons in actionscript 3.0?

I am a little bit new in this programming stuff and I need help to program in ActionScript 3.0 (Adobe Animate CC). I want to make a symbol (graph) visible but only after clicking in two different buttons (button1 and button 2). I can make that with just one button, but I can't make it with two buttons... Can anyone help me? I tried this code but it isn't working as it should:
button1.addEventListener (MouseEvent.CLICK, fl_MouseClickHandler_1);
button2.addEventListener (MouseEvent.CLICK, fl_MouseClickHandler_1);
function fl_MouseClickHandler_1(event:MouseEvent):void
{
graph.visible = true;
}
Tom
Simplest way would be to do this, although there may be other ways to do it as well:
var isButton1Clicked:Boolean = false;
var isButton2Clicked:Boolean = false;
button1.addEventListener (MouseEvent.CLICK, fl_MouseClickHandler_1);
button2.addEventListener (MouseEvent.CLICK, fl_MouseClickHandler_1);
function fl_MouseClickHandler_1(event:MouseEvent):void
{
if (event.currentTarget == button2)
isButton2Clicked = true;
else if (event.currentTarget == button1)
isButton1Clicked = true;
if (isButton1Clicked && isButton2Clicked)
{
graph.visible = true;
isButton1Clicked = isButton2Clicked = false;
}
}
Note that I reset both the Boolean values to false, once the graph is visible so that it works like a reset.
On a side note, I would recommend to use better names for your buttons and your event handlers. Just best practice.
Hope this helps. Cheers.

After end of MouseMove or drag event menu keeping from release menu items

I am having a problem with draggable menu including menu button items.
At the end of drag operation (when I lift my finger from the screen) a button sub item works because of its MOUSE_UP code.
I need drag end drop my menu. After drop menu button items listeners should start for release (MOUSE_UP). How can I separete them?
I read some similar messages but I couldnt solve my problem.
My code:
addEventListener(MouseEvent.MOUSE_MOVE, dragStart);
addEventListener(MouseEvent.MOUSE_UP, dragStop);
function dragStart(e:MouseEvent):void {
e.currentTarget.startDrag(false,new Rectangle(0,0,500,0));
}
function dragStop(e:MouseEvent):void {
e.currentTarget.stopDrag(false,new Rectangle(0,0,500,0));
}
Thanks..
My sample file is here
update:
I was getting it wrong. I'd suggest switching a flag in the parent clip when it is dragged and ignore MOUSE_UP events in children if it is true.
In the parent:
var dragging:Boolean = false;
function dragStart(e:MouseEvent):void{
e.currentTarget.startDrag(false,new Rectangle(0,0,500,0));
dragging = true;
}
function dragStop(e:MouseEvent):void{
e.currentTarget.stopDrag();
removeEventListener(MouseEvent.MOUSE_MOVE, dragStart);
dragging = false;
}
In subItem:
function BTN(e:MouseEvent):void{
if(!(parent as MovieClip).dragging){
trace("I'm a button: "+this+" Did you hit me when you sliding?");
}
}

Image scroller that disables left arrow or right arrow based on the position of mc

I created sort of a nifty image scroller that scrolls a movieclip right or left based on a relative tween. I would however like to add an if statement or something, so that when the movieclip gets to a certain position, either the left direction arrow is disabled or the right direction arrow is disabled. Here is the code I have so far:
import flash.display.MovieClip;
import flash.events.MouseEvent;
import com.greensock.*;
import com.greensock.easing.*;
function init():void{
TweenLite.to(products_mc, 1, {x:696, alpha:1});
}
init();
checkPositionR();
function productsLeft(events:MouseEvent):void
{
TweenLite.to(products_mc, .75, {x:"-255"});
arrowR_btn.visible = true;
arrowR_btn.buttonMode = true;
checkPositionL();
}
function productsRight(events:MouseEvent):void
{
TweenLite.to(products_mc, .75, {x:"255"});
arrowL_btn.visible = true;
arrowL_btn.buttonMode = true;
checkPositionR();
}
function checkPositionR():void
{
if (products_mc.x = 696) {
arrowR_btn.visible = false;
arrowR_btn.buttonMode = false;
}
}
function checkPositionL():void
{
if (products_mc.x = -1086) {
arrowL_btn.visible = false;
arrowL_btn.buttonMode = false;
}
}
arrowL_btn.buttonMode = true;
arrowL_btn.addEventListener(MouseEvent.CLICK, productsLeft);
arrowR_btn.buttonMode = true;
arrowR_btn.addEventListener(MouseEvent.CLICK, productsRight);
arrowL_btn.doubleClickEnabled = true;
arrowR_btn.doubleClickEnabled = true;
arrowL_btn.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler, false);
arrowR_btn.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler, false);
function doubleClickHandler(evt:MouseEvent):void
{
evt.stopPropagation();
}
If you remove the checkPositionR() and checkPositionL() functions from the productsRight() and productsLeft() functions, you'll see this works ok, however then it ignores the toggle the button off. Basically this is just scrolling a movie clip left or right and I want it to not be able to scroll beyond a certain point in either direction. (or loops)
Any ideas? Thanks!
(yes I could do this on the timeline alot easier but I think this cool be as scripted)
try using an if statement in productsRight/Left that will only run if the object's x value is with in a certain limit.
productsRight:
if(products_mc.x < 696){
//your Code
}
productsLeft:
if(products_mc.x > -1086){
//your Code
}
OK i found the perfect solution:
http://www.flashuser.net/build-an-image-slideshow-in-flash
However now I'm wondering, if there a way to do this on multiple movieclips at once with one click?

Action Script 3. How to hide button till game ends?

I'm creating game and I need to make that when game over "Try Again" button appears. I have done the button just don't know how to hide It till game ends. It is shown all the time.
This is my button:
function tryAgain(e:MouseEvent):void
{
trace("Try again");
createCards();
}
button.visible = false;
function tryAgain(e:MouseEvent):void
{
button.visible = true;
createCards();
}
visible property on AS3 Reference
Use "visibility" property to hide DisplayObject's (Button or SimpleButton are DisplayObject's).
button.visible = false;

Flash AS3: How to Make scroll bar react to dynamic textfield movement?

I've been looking for a tutorial and answer to this for a while but can't find what I'm looking for. I am loading html text into a dynamic textfield, and I have a scrollbar controlling the scroll using the code below. What I want to do is also add scroll up/down buttons and have the scroll bar move in relation to the text scroll. I was just going to use "tracklistingtext.scrollV -- " for the scroll buttons, but right now the scroll bar doesn't recognize the text movement. What do I need to do to get the scroll bar to listen to the text scroll position?
var listTextreq:URLRequest=new URLRequest("tracklist.txt");
var listTextLoader:URLLoader = new URLLoader();
var bounds:Rectangle=new Rectangle(scrollMC.x,scrollMC.y,0,300);
var scrolling:Boolean=false;
function fileLoaded(event:Event):void {
tracklistingtext.htmlText=listTextLoader.data;
tracklistingtext.multiline=true;
tracklistingtext.wordWrap=true;
scrollMC.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
addEventListener (Event.ENTER_FRAME, enterHandler);
}
listTextLoader.addEventListener(Event.COMPLETE, fileLoaded);
listTextLoader.load(listTextreq);
function startScroll(e:Event):void {
scrolling=true;
scrollMC.startDrag(false,bounds);
}
function stopScroll(e:Event):void {
scrolling=false;
scrollMC.stopDrag();
}
function enterHandler (e:Event):void {
if (scrolling == true) {
tracklistingtext.scrollV = Math.round(((scrollMC.y - bounds.y)/300)*tracklistingtext.maxScrollV);
}
}
Any help is greatly appreciated.
Replace the scrollHandler calculations with yours.
//...
function fileLoaded(event:Event):void {
tracklistingtext.htmlText=listTextLoader.data;
tracklistingtext.multiline=true;
tracklistingtext.wordWrap=true;
scrollMC.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
addEventListener (Event.ENTER_FRAME, enterHandler);
/* !!! */ tracklistingtext.addEventListener(Event.SCROLL, scrollHandler);
}
//...
function scrollHandler(event:Event):void {
scrollMC.y = (tracklistingtext.scrollV / tracklistingtext.maxScrollV) * bounds.height + bounds.y;
}