Actionscript help for a noob?

A place for tutorials on how to get the most out of Flash

Actionscript help for a noob?

Postby Eggplants » Sun Feb 05, 2012 11:35 am

Hey guys I've really been trying to do things on my own but alas I'm too much a noob at action script :cry:

I have two questions which I hope are not too complicated
One) I got somewhat far in my sound controls but I don't know how to add them on top of each other. My code currently looks like this and is attached to a button.
bruburu1.png
bruburu1.png (17.43 KiB) Viewed 5155 times
I pretty much want to get the highlighted part and make it happen again with a different sound when "snowLine1" finishes but I don't know how to add it in.

& Two) How do I tie the preloader to a hundred frame animation? I think I've seen this before but I can't find it in actionscript 2.0. this is my animation but I've no idea how it's done. Even if you could show me a tutorial that'd be great.
Click to Play
(Javascript Required)

Eggplant Loader beta.swf [ 3.49 KiB | Viewed 5155 times ]



This is why I've been doing pretty much nothing as of late so if I could finally get past this hurdle I can get back to doing what I love doing and what you love(?) seeing.
And hey if you help me out here, if you want I could even share some tips with my own tutorial about drawing and/or animating like smoothness or shape tweens.
I animate and draw stuff! Check out my gallery if you wish.
Also my email is [email protected]. I'm always happy to receive emails ;)
User avatar
Eggplants
LoK Team Member
 
Joined: Sun Jun 06, 2010 5:55 pm
Location: livin on the ceiling

Re: Actionscript help for a noob?

Postby GoRepeat » Sun Feb 05, 2012 3:02 pm

On the loader movie clip:

Code: Select All Code
onClipEvent(enterFrame){
_root.loadper = ((Math.floor(_root.getBytesLoaded()/ getBytesTotal()*100))+1);
this.gotoAndStop(_root.loadper);
_root.loadtxt.text = _root.loadper;
}


The first line sets it to the percentage loaded + 1 (there is no frame 0).
The second line will tell the clip to go to whatever frame the percentage is at (1-101)
Third line will show the % number in a dynamic text box on the main stage called "loadtxt"
Frame 101+ should be the "Load Complete" part of the animation.

As for the sounds, if you tie the linked name to a variable, you can have them loop against one another.
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Actionscript help for a noob?

Postby dirtyc101 » Sun Feb 05, 2012 4:13 pm

Not related to your question at all, but I see an error in your code that's going to cause you fits.

Code: Select All Code
if (playing  != true)

Should instead say
Code: Select All Code
if (playing  !== true)


A single = sets the value, so in this case you're setting the variable playing to not equal true (I guess it would set it to false then?)
A double == is a query, asking if the values are equal.

Hope I helped.
-DirtyC101

EDIT: Just occurred to me I'm assuming you are using AS2. What I said is probably true in AS3 as well, but honestly don't know.
dirtyc101
 
Joined: Fri May 21, 2010 10:18 pm

Re: Actionscript help for a noob?

Postby BlueLight » Sun Feb 05, 2012 6:13 pm

dirtyc101 Wrote:Not related to your question at all, but I see an error in your code that's going to cause you fits.

Code: Select All Code
if (playing  != true)

Should instead say
Code: Select All Code
if (playing  !== true)


A single = sets the value, so in this case you're setting the variable playing to not equal true (I guess it would set it to false then?)
A double == is a query, asking if the values are equal.

Hope I helped.
-DirtyC101

EDIT: Just occurred to me I'm assuming you are using AS2. What I said is probably true in AS3 as well, but honestly don't know.


Very strange. in java you normally have a equals operator to the right of any other operator when doing a query .
Code: Select All Code
== is A and B equal?
!= Is A and Be not equal?
<= is A equal or less than B?
>= is A greater or equal to B?
we also have

< a is less than B
> A is more than B

Can't think of any others.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby GoRepeat » Sun Feb 05, 2012 6:13 pm

In AS2 it would just be:

Code: Select All Code
if(!playing){


You just need to put the ! in front of the statement to check for false, or leave it out for true -> if(playing)
The == true/false isn't necissary unless you are looking for a specific value -> if(playing==1);
For booleans you can just use the variable with or without !

This works for almost all commands. For example:

if(this.hitTest(that)) -> if this hits that
if(!this.hitTest(that)) => if this does not hit that
if(Key.isDown(key.SPACE)) -> if space is down
if(!Key.isDown(key.SPACE)) -> if space is not down

AS2 is a very simple and user friendly language. Why I love it so much!
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Actionscript help for a noob?

Postby BlueLight » Sun Feb 05, 2012 6:38 pm

Gorepete Wrote:In AS2 it would just be:

Code: Select All Code
if(!playing){


You just need to put the ! in front of the statement to check for false, or leave it out for true -> if(playing)
The == true/false isn't necissary unless you are looking for a specific value -> if(playing==1);
For booleans you can just use the variable with or without !


This is because a if statement checks to see if all the logical statements are true.
If all statements are true than the if statement is true.

Boring logic stuff that might help but i was rushed. I was going to put it in a spoiler anyways.
Not sure if the logic is totally clear and correct since as i said it was rushed.
Spoiler (click to show/hide):

tip: what your doing a if statement you can't do something like
Code: Select All Code
if(a && B || C);

what this code is saying is A and B or C which logically doesn't make sense. (Ya i have to go in to logic here because it's just that. Logic!)
This is because in logic we don't know what gets used first 'or', or the 'and'.


We don't know if we're saying (A and B) or C, or if it's A and (B or C). If you were to say A is a ice cream cone and B and C are flavors than the first logic wouldn't make sense.
Code: Select All Code
(A and B) or C
if((ice cream cone and bubblegum ice cream are true) Or chocolate is true)
This will not work because you might get chocolate true and no ice cream cone.

but if we say
Code: Select All Code
if(ice cream cone and (bubblegum or chocolate is true))
We're saying if you have a  ice cream cone and either of the two ice cream has to be true.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby hat973 » Sun Aug 18, 2013 3:57 am

Im trying to make custom name thing so people can name the main character dose anyone know a code for that
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby BlueLight » Sun Aug 18, 2013 4:23 am

hat973 Wrote:Im trying to make custom name thing so people can name the main character dose anyone know a code for that

Hat i don't mean to scare you but...... You should be scared!
Doing something like this in general is fairly easy.



public class A {
//variable for the player name. This will be a string since strings are perfect for text... unless you have a password.
private String playerCharacterName = "";

//this method setter gets a String and makes that string the player's name.
public void setPlayerName(String text){
this.playerCharacterName = text;
}

//when this method get called, the player's name is returned as a string.
public String getPlayerName(){
return this.playerCharacterName;
}




Okay, for starters this is java code,
Second this should be easy for starting people to do. Maybe you'd forgo the Getter and setter and just make the variable public, but it's still something basic that you should know how to do.
Third, if you're talking about help for a GUI component then you need to be a little bit more forth coming with information. The general theory is that you add a listener to one of the components, like an actionlistener to a button; then you program the listener to take information from a TextField and send it to the "SetPlayerName(String text);" method.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby hat973 » Sun Aug 18, 2013 4:31 am

BlueLight Wrote:
hat973 Wrote:Im trying to make custom name thing so people can name the main character dose anyone know a code for that

Hat i don't mean to scare you but...... You should be scared!
Doing something like this in general is fairly easy.



public class A {
//variable for the player name. This will be a string since strings are perfect for text... unless you have a password.
private String playerCharacterName = "";

//this method setter gets a String and makes that string the player's name.
public void setPlayerName(String text){
this.playerCharacterName = text;
}

//when this method get called, the player's name is returned as a string.
public String getPlayerName(){
return this.playerCharacterName;
}




Okay, for starters this is java code,
Second this should be easy for starting people to do. Maybe you'd forgo the Getter and setter and just make the variable public, but it's still something basic that you should know how to do.
Third, if you're talking about help for a GUI component then you need to be a little bit more forth coming with information. The general theory is that you add a listener to one of the components, like an actionlistener to a button; then you program the listener to take information from a TextField and send it to the "SetPlayerName(String text);" method.


thanks for the help blue light -.- iv been poking around the web all day looking for this and all i could find is how to put money in but it only talks about how u get it when u kill a bad guy in a Fighting RPG im doing a Animal crossing style
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby BlueLight » Sun Aug 18, 2013 4:40 am

Again this is fairly basic stuff. this is the kinda thing you learn with second or third versions of Hello world.
Not trying to be harsh or insult you. It's just that i'm worried since this is fundamental stuff
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby hat973 » Sun Aug 18, 2013 4:43 am

BlueLight Wrote:Again this is fairly basic stuff. this is the kinda thing you learn with second or third versions of Hello world.
Not trying to be harsh or insult you. It's just that i'm worried since this is fundamental stuff


I only lurned a few codes like play and pause button thats it my teacher never really went over all the codes only for those on movie making
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby BlueLight » Sun Aug 18, 2013 4:47 am

hat973 Wrote:
BlueLight Wrote:Again this is fairly basic stuff. this is the kinda thing you learn with second or third versions of Hello world.
Not trying to be harsh or insult you. It's just that i'm worried since this is fundamental stuff


I only lurned a few codes like play and pause button thats it my teacher never really went over all the codes only for those on movie making

:shock:

Okay, well the first application you should ever make is something called "Hello World" and it's stupid simple!
I think this is a video for AS3 on how to do it. http://www.adobe.com/devnet/archive/fla ... class.html

and this seems to be a AS2 tutorial http://www.nidoweb.com/as2.php
You should really pick up a book on AS2 or AS3. I'd go with AS3 since it's closer to normal 'C' Programming but that's up to you.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby hat973 » Sun Aug 18, 2013 5:07 am

BlueLight Wrote:
hat973 Wrote:
BlueLight Wrote:Again this is fairly basic stuff. this is the kinda thing you learn with second or third versions of Hello world.
Not trying to be harsh or insult you. It's just that i'm worried since this is fundamental stuff


I only lurned a few codes like play and pause button thats it my teacher never really went over all the codes only for those on movie making

:shock:

Okay, well the first application you should ever make is something called "Hello World" and it's stupid simple!
I think this is a video for AS3 on how to do it. http://www.adobe.com/devnet/archive/fla ... class.html

and this seems to be a AS2 tutorial http://www.nidoweb.com/as2.php
You should really pick up a book on AS2 or AS3. I'd go with AS3 since it's closer to normal 'C' Programming but that's up to you.


ya i made something like hello world a year or 2 ago it was our warm up thing to get to know flash
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby OwnerOfSuccuby » Wed Aug 21, 2013 5:03 pm

Hello every one i am back :mrgreen:

By the way about this tipic - do all work now or there are some more questions about loader and sounds ? May be i can help ?
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Actionscript help for a noob?

Postby Terrantor!!! » Wed Aug 21, 2013 10:24 pm

I got a question.
Why is there a pause before movement in this clip? For example it seems the entire movie clip plays before her x-coordinate begins to change.
Spoiler (click to show/hide):

Click to Play
(Javascript Required)

kryrig.swf [ 22.87 KiB | Viewed 4576 times ]

User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Actionscript help for a noob?

Postby OwnerOfSuccuby » Thu Aug 22, 2013 5:11 am

Terrantor!!! Wrote:I got a question.
Why is there a pause before movement in this clip? For example it seems the entire movie clip plays before her x-coordinate begins to change.
Spoiler (click to show/hide):

kryrig.swf


You have to make movment on timer / enter frame or the same way.

Now as i understand you made it on button press ? I do not know why but flash work so - it checks first press then thinks some time and after that start to check is button press or not.

So to make it smoth - on enter frame -> if button is pressed -> function that you have to execute,

For example in AS3:

Code: Select All Code
function MyPlayerMovment():void{
 
   //Ship Animation and movment
    if (MoveType=="FlyStage"){//Movie algoritms
     if ((StarShipFirstStagemoveLeft==0)&&(StarShipFirstStagemoveRight==1)){
      PlayerPositionToPlay=1;
      if ((Player1.x<StarShipFirstStageRightLimit)&&(StarShipFirstStagemoveUp==1)){Player1.x+=StarShipFirstStageSpeed;}
     }
     if ((StarShipFirstStagemoveLeft==1)&&(StarShipFirstStagemoveRight==0)){
      PlayerPositionToPlay=2;
      if ((Player1.x>StarShipFirstStageLeftLimit)&&(StarShipFirstStagemoveUp==1)){Player1.x-=StarShipFirstStageSpeed;}
     }
   
       
     Player1.gotoAndStop(PlayerPositionToPlay);
    

}// если FlyStage
}


  // Принажатии на клавиши что делать
  //What to do if key is pressed

function myPlayerMovier(e:KeyboardEvent):void{
    if (MoveType=="FlyStage"){
      switch (e.keyCode) {
        case myKeyKodeLeft :
          StarShipFirstStagemoveLeft=1;
        break;
        case myKeyKodeUp :
        if ((StarShipFirstStagemoveUp==0)&&((root as MovieClip).CHF>0)){
            StarShipFirstStagemoveUp=1;
          vel=13;
         Player1.Player1.gotoAndPlay(2);
        }
        break;
       case myKeyKodeRight :
          StarShipFirstStagemoveRight=1;
        break;
          case myKeyKodeFire :
        if ((StarShipFirstStagemoveUp==0)&&((root as MovieClip).CHF>0)){
            StarShipFirstStagemoveUp=1;
          vel=13;
         Player1.Player1.gotoAndPlay(2);
        }
        break;
      }
    }//if CRun
}

  //При отпускании клавиши что происходит
  //what to do when key is released
function myPlayerUnMovier(e:KeyboardEvent):void{
    if (MoveType=="FlyStage"){
      switch (e.keyCode) {
        case myKeyKodeLeft :
          StarShipFirstStagemoveLeft=0;
        break;
       case myKeyKodeRight :
          StarShipFirstStagemoveRight=0;
        break;
      }
    }//if CRun
}


And in AS2 :

Code: Select All Code
onClipEvent(enterFrame) {
   if(_root.movement or _root.movementright) {
      if(Key.isDown(Key.RIGHT)) {
         _x += _root.movespeed;
         right = true;
         gotoAndStop(2);
      } else if(right)
         gotoAndStop(1);
   }

   if (_root.movement or _root.movementleft) {
      if(Key.isDown(Key.LEFT)) {
         _x -= _root.movespeed;
         right = false;
         gotoAndStop(4);   
      } else if(!right)
         gotoAndStop(3);
   }
}
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Actionscript help for a noob?

Postby GoRepeat » Thu Aug 22, 2013 8:49 pm

To expound a bit on what Succy was saying:

The simple answer is that they broke the crap out of arcade style key response in AS3. There is always a slight jag or pause between the event listener and the actual trigger occurring. So what you must do is create a boolean to control the action, then tie that boolean to the trigger key itself. This way, the game is always checking to see if the boolean is true or false instead of checking to see if the key is pressed. An example:

This code will cause the lag/pause:
Code: Select All Code
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPress);

function keyPress(e:KeyboardEvent):void{
    switch(e.keyCode){
        case 37: character.x -= 10; break;
        case 39: character.x += 10; break;
    }
}


To work around the issue we set it up like this instead:
Code: Select All Code
var keyArray:Array = new Array(37,39,false,false);

stage.addEventListener(Event.ENTER_FRAME, frameLoop);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPress);
stage.addEventListener(KeyboardEvent.KEY_UP, keyRelease);

function frameLoop(e:Event):void{
    checkMovement();
}

function keyPress(e:KeyboardEvent):void{
    switch(e.keyCode){
        case keyArray[0]: keyArray[2] = true; break;
        case keyArray[1]: keyArray[3] = true; break;
    }
}

function keyRelease(e:KeyboardEvent):void{
    switch(e.keyCode){
        case keyArray[0]: keyArray[2] = false; break;
        case keyArray[1]: keyArray[3] = false; break;
    }
}

function checkMovement():void{
    if(keyArray[2]){
        character.x -= 10;
    }
    if(keyArray[3]){
        character.x += 10;
    }
}


It is a bit more cumbersome, but that is the price for using AS3 event listeners. Once you have the basic structure set up, though, you can just add additional key codes and a matching boolean to the array and work from there. Hope that helps.
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Actionscript help for a noob?

Postby Terrantor!!! » Thu Aug 22, 2013 9:59 pm

Thanks for trying, i went back to AS2, though, it just works better, that way.:-(
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Actionscript help for a noob?

Postby GoRepeat » Fri Aug 23, 2013 12:17 pm

Terrantor!!! Wrote:Thanks for trying, i went back to AS2, though, it just works better, that way.:-(



Haha, sadly, for stuff like this, it really does! The only reason I ended up switching to AS3 was for mobile gaming
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Actionscript help for a noob?

Postby Terrantor!!! » Sat Aug 24, 2013 4:03 am

How would I go about collision? I'm very into concise coding. I would like it to be as simple as possible. For example, I just wanna make an invisible hit box for krystal and put it on a enterFrame event. And when that hit box touches another, a code occurs. Is there a way or a better way to do that?
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Next

Return to Tutorials



Who is online

Users browsing this forum: No registered users