-
1. Re: Help with AS3
Ned Murphy Jan 14, 2010 3:20 PM (in response to TorQue[MoD])The problem stems from using specific x locations for the end points of the tweens, x=-600 and x=+600.
I think you want to use content_mc.x-600 and content_mc.x+600 for those values
-
2. Re: Help with AS3
TorQue[MoD] Jan 14, 2010 4:20 PM (in response to Ned Murphy)In the video tutorial I was watching, he had used a specific value for the ending position and it worked fine in his example.Either way, I updated my code to:New Code stop();//Home Page Tween Class Code
import fl.transitions.Tween;
import fl.transitions.easing.*;
//Handle button events
left.addEventListener(MouseEvent.CLICK, clickLeft);
right.addEventListener(MouseEvent.CLICK, clickRight);//Add code for Right Click Pan
function clickRight(evtObj:MouseEvent){
var RightTween:Tween = new Tween(content_mc, "x", Regular.easeOut, content_mc.x, content_mc.x-500, 1, true);
}
//Add code for Left Click Pan
function clickLeft(evtObj:MouseEvent){
var LeftTween:Tween = new Tween(content_mc, "x", Regular.easeOut, content_mc.x, content_mc.x+500, 1, true);
}
And it works! My only question now is how do I define a starting and ending point for the clip so it doesn't keep scrolling indefinitely?Right now, once it gets to the end of the mc, I can keep clicking right until the cows come home and the same thing happens when I get back to the beginning.
There's also the issue of my content having a width of 8000 pixels and it seems that flash can only display 4000 pixels before the rest of the image simply disappears off stage. Even if I zoom out to 25% there's a hard limit to the viewable area. Is there a way to increase this?
Thank you.
-
3. Re: Help with AS3
Ned Murphy Jan 14, 2010 4:23 PM (in response to TorQue[MoD])I can't speak for the tutorial you mention except to say many folks miss things when they prepare tutorials. There would be no reason to use +/- symbols in front of those numbers unless the intention was really to do what I suggested. It's possible the sample worked because it had the code done correctly.
As for stopping the motion you need to place conditions on allowing the tweens to be executed. The movieclip will have an x value that it should not exceed in both directions. Let's say the movieclip was initially at x=0. By rights, you never want that movie's x property to go higher than 0, otherwise it moves to the right going out of the primary viewing area. So you build in a restriction for allowing the tween...
function clickLeft(evtObj:MouseEvent){
if(content_mc.x <= -500){var LeftTween:Tween = new Tween(content_mc... etc....);
}
}Similarly, for the tween going the other way, there is a value that relates to both the width of the movieclip and the width of the viewing area such that it should never move off to the left and leave the viewing area partially filled or empty.
-
4. Re: Help with AS3
TorQue[MoD] Jan 14, 2010 4:49 PM (in response to Ned Murphy)Thank you so much for the help. I'll see if I can get something like that working.Its hard to know what you can type in AS to make anything happen. In Dreamweaver there's code hinting and auto code generation so I can either just "Insert" what I need or start typing letters and see what comes up in the pop up list. I tried turning on Script Assist but it doesn't seem to work quite as easily as Dreamweaver's code assist.I really only know how to do anything based on what the tutorial covered which is pretty much limited to everything that I've coded so far.I'm not quite clear on how to use an if statement properly.Your example is if(content_mc.x <= -500){Lets see if I understand what this means. I'll just try to explain it in plain english...if the content_mc's X value is less than or equal to -500 then continue on to the next line of code.Is that right?
The basic idea of what I want to implement is that my content_mc is 8000 pixels wide by 700 high and I want it to stop once it gets to the far right side of the stage and similarily when it gets to the far left too.So I would use:If Statement //Add code for Right Click Pan
function clickRight(evtObj:MouseEvent){
if(content_mc.x <= -8000){
}
var RightTween:Tween = new Tween(content_mc, "x", Regular.easeOut, content_mc.x, content_mc.x-1000, 1, true);
}
//Add code for Left Click Pan
function clickLeft(evtObj:MouseEvent){
if(content_mc.x <= 0){
}
var LeftTween:Tween = new Tween(content_mc, "x", Regular.easeOut, content_mc.x, content_mc.x+1000, 1, true);
}To me this looks like its giving an if statement to allow the right and left mouse buttons to move the X position an extra 1000
So its saying if the X position is already at -8000 then DO NOT allow it to move anymore, but if it isn't then go ahead?
Is that correct?
Also, I've noticed that you can increase the stage size (to a maximum of 2880 pixels) but you can't increase the grey space around the stage. This presents an issue when I want to add text to the far left side of my movie_clip that is currently off stage. Any idea how to do this?
-
5. Re: Help with AS3
Ned Murphy Jan 14, 2010 6:47 PM (in response to TorQue[MoD])Your if statements won't control anything because the code lies outside them. If you look at my example you'll see how the code is inside the if's curly braces, not after them. And you're pretty much correct... if the condition being tested evaluates as true, process the code within the conditional, otherwise, do nothing inside that conditional.
As far as determining what values you need to apply, that's not really a coding issue, just a mathematics problem to solve. Normally for something that moves in a 'displayarea' you have to control the endpoints... one is usally just a simple value, the other end usually involves consideration for the width of the object and the display width. You have to think in terms of how to control the value of x to keep things where you want them in the display area.
-
6. Re: Help with AS3
TorQue[MoD] Jan 14, 2010 9:06 PM (in response to Ned Murphy)What I mean was that I wasn't even aware that you could call an if statement in flash. The only programming I've ever done before this is html. Using html as an example, if I didn't know image tag code, I wouldn't exactly be able to figure out how to add images to my websites. However with Dreamweaver, since I can go to Insert - Image and then look at the code dreamweaver generates, I can easily learn that the code to insert and image is <img src="image1.jpg"> and therefore in the future, I can type the code myself.At this point in time, I don't know a single thing about AS so I don't even know what my options are let alone how to properly call anything.Ok, so here's my updated code:If Statement Working stop();//Home Page Tween Class Code
import fl.transitions.Tween;
import fl.transitions.easing.*;
//Handle button events
left.addEventListener(MouseEvent.CLICK, clickLeft);
right.addEventListener(MouseEvent.CLICK, clickRight);//Add code for Right Click Pan
function clickRight(evtObj:MouseEvent){
if(content_mc.x <= -7000){
var RightTween:Tween = new Tween(content_mc, "x", Regular.easeOut, content_mc.x, content_mc.x-1000, 1, true);
}
}
//Add code for Left Click Pan
function clickLeft(evtObj:MouseEvent){
if(content_mc.x <= 0){
var LeftTween:Tween = new Tween(content_mc, "x", Regular.easeOut, content_mc.x, content_mc.x+1000, 1, true);
}
}This however, isn't giving me the results I desire. Seeing as how the mc width is 8000 and I'm moving in 1000 increments, I made the X amount 7000 but its still moving past the desired point. In fact, it will let me move past the desired point and then when I start moving back to the left, it will restrict movement about 3,000 pixels back to the left.
What this tells me is that the numbers are wrong. The only problem is that since the MC starts at 0 with the rest of the clip existing 7,000 pixels to the right, with this current code, if I click on the left button from the start, it will move the mc to the left. I need it to NOT allow movement past position 0 or past position 7,000 so I'm not sure I'm using the correct if statement here. Can you use less than statements as well?
if(content_mc.x >= -7000){
And right now this setup is saying "If the X position IS less than ###, then allow the Tween to work. How do I change it to instead say something like if the X position is = ###, then DO NOT allow the tween to work. I think that would be better.
Something like"
if(content_mc.x = -7000){
//DO NOT let this tween work:
var RightTween:Tween = new Tween(content_mc, "x", Regular.easeOut, content_mc.x, content_mc.x-1000, 1, true);}
if(content_mc.x = 0){
//DO NOT let this tween work:
var LeftTween:Tween = new Tween(content_mc, "x", Regular.easeOut, content_mc.x, content_mc.x+1000, 1, true);}


