View unanswered posts | View active topics



Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3
FD3 Sample projects 
Author Message
Member

Joined: Sun Oct 11, 2009 3:55 am
Posts: 4
Thank you for the reply.
The sample project does that (already has a component.swc) built, and a 'button' is created, but it is without the background, just the text.
I know that the button has 4 image files that are used for 'up' 'down', 'over' etc, and I believe these are not being included or made available.
I read an article about using Flash Assets in AS3, but couldn't follow it.
http://blogs.adobe.com/flexdoc/pdf/swf9.pdf
Do I have to put the skins back into the component in a new way myself?
Thanks


Sun Oct 11, 2009 4:41 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
When you create a SWC in Flash CS by dropping a UI component like a button, the skin will be included as well.

So maybe there's a problem in your code - did you give the button a size (width, height)? Is alpha set to 0 (this would hide the skin but not the text)?


Sun Oct 11, 2009 6:52 pm
Profile WWW
Member

Joined: Sun Oct 11, 2009 3:55 am
Posts: 4
I didn't create the SWC, I used the one in the sample (earlier in this thread). I assumed that was done right. Also, all I did was to 'add' a button. Here is the code :
Code:
package
{
   import fl.controls.Button;
   import fl.controls.ColorPicker;
   import fl.controls.Label;
   import flash.display.Sprite;
   import flash.events.Event;
   import flash.text.TextFieldAutoSize;
   
   public class Main extends flash.display.Sprite
   {
      private var chooseLabel:Label;
      private var picker:ColorPicker;
      private var gfx:TestGraphic;
      
      public function Main():void
      {
         stage.scaleMode = "noScale";
         
         chooseLabel = new Label();
         chooseLabel.y = 4;
         chooseLabel.autoSize = "left";
         chooseLabel.text = "Choose a color:";
         addChild(chooseLabel);
         
         picker = new ColorPicker();
         picker.x = 100;
         addChild(picker);
         picker.addEventListener(Event.CHANGE, pickedColor);
         
         gfx = new TestGraphic();
         gfx.y = 30;
         addChild(gfx);
         
         var button:Button = new Button();
         button.setSize(100, 30);
         button.label = "Clickme";
         button.move(50, 220);
         addChild(button);
      }
      
      private function pickedColor(e:Event):void
      {
         gfx.opaqueBackground = picker.selectedColor;
      }
   }
}


I do have FlashCS4 installed on my machine, if that makes any difference.


Sun Oct 11, 2009 8:03 pm
Profile
Member

Joined: Sun Oct 11, 2009 3:55 am
Posts: 4
OK, i figured it out. finally had the sense to look at the swc that I downloaded, and it turns out the skins are not in it. Will rebuild the swc and try again, but I am sure it will work now.

Thanks


Sun Oct 11, 2009 8:08 pm
Profile
Member

Joined: Wed Feb 10, 2010 10:54 pm
Posts: 7
questions dropped.

Thanks!


Mon Sep 20, 2010 10:10 pm
Profile
Member

Joined: Wed Dec 01, 2010 8:09 am
Posts: 9
thanks for useful information...


Fri Dec 10, 2010 10:51 am
Profile
Member

Joined: Mon Jan 03, 2011 11:35 pm
Posts: 6
Okay, I'm starting to get it, but I just need a liiittle more help here :)

For this game I'm making, I have enemies in different colors, so I'll use GreenEnemy here to explain my problem:

- In my FLA Library, I've exported the MC GreenEnemy as GreenEnemy (base class is flash.display.MovieClip).
- GreenEnemy is supposed to extend Enemy, which holds the enemy AI etc. Enemy is not a graphical asset, it's not in the library, but it extends MovieClip.
- I tried to put just Enemy as base class for GreenEnemy, but it didn't work. Flash tells me: "A definition for the base class could not be found in the class path...". I've placed Enemy.as among my other classes (everything worked when I was still compiling with the Flash IDE).

So, my question is simply, what do I have to do to make GreenEnemy extend my Enemy class?


Tue Jan 04, 2011 2:48 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Making your library symbols extend your code is a good decision, but make sure the base code is as simple as possible - ie. not referencing too much other classes that may lead Flash CS to compile your entire project.

Now for this to work, the FLA must be able to resolve this base class, ie. it must be in your FLA's classpath (see Flash Publish settings).


Tue Jan 04, 2011 4:14 pm
Profile WWW
Member

Joined: Mon Jan 03, 2011 11:35 pm
Posts: 6
Quote:
Making your library symbols extend your code is a good decision, but make sure the base code is as simple as possible - ie. not referencing too much other classes that may lead Flash CS to compile your entire project.


This is going to be a problem, because as of now, I have an Engine class that kind of works like the spider in the web; it puts all the objects on stage and have a whole bunch of other features. Here's an example of a method I have in my Enemy base class:

Code:
      private function removeEnemy():void {
         
         dispatchEvent(new Event("EnemyKilled"));
         removeEventListener(Event.ENTER_FRAME, loop);
         removeEventListener(TimerEvent.TIMER, rndmBehaviour);
         
         if (Engine.sky.contains(this)) {
            Engine.sky.removeChild(this);
         }
      }


- Engine is the main class for the game and "sky" is a Sprite that contains all the enemies.

Here's another example. This snippet is from my Bullet/Weapon base class and basically checks if it makes contact with an enemy:
Code:
for (var i:int = 0; i < Engine.enemyList.length; i++){
            if (hitTestObject(Engine.enemyList[i])) {


- enemyList is an array that keeps track of all the present enemies.

In fact, it's already become a problem, because now Flash throws me this new error:
1120: Access of undefined property Engine.

Not good! :( Please help!


Tue Jan 04, 2011 9:13 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Well you are doing it wrong but this is going to be very difficult to explain it simply...

The idea is that the Engine should iterate over the enemies array and decide which enemy should be removed.

May I suggest a book?
http://www.8bitrocket.com/books/the-ess ... ash-games/


Tue Jan 04, 2011 10:00 pm
Profile WWW
Member

Joined: Mon Jan 03, 2011 11:35 pm
Posts: 6
I've aldready got Learning ActionScript 3.0 - A Beginners Guide, ActionScript 3.0 Game Programming University, Essential ActionScript 3.0, Foundation Actionscript 3.0 Animation - Making Things Move and Actionscript 3.0 Bible but should I still read the one that you suggested? I haven't actually finished them yet though, just to be clear :p

Quote:
Well you are doing it wrong but this is going to be very difficult to explain it simply...
The idea is that the Engine should iterate over the enemies array and decide which enemy should be removed.


Hm, okay. That's bad news :( What would you suggest me to do? Should I put the game on hold and finish the books first (I'm currently in the middle of Learning ActionScript 3.0 - A Beginners Guide) or should I roll back all changes I've done with FD and finish the game "my way" (even though it's not the right way), and read the books after? It's hard to know what's best for you when you're still a beginner you know :/


Tue Jan 04, 2011 10:25 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Ok you have books, great ;)

Well then to develop a game you need a game loop, for instance using an ENTER_FRAME event handler.
In the game loop, you will update the entire game state - move the player, the enemies, weapons, kill enemies etc.

Code in the Enemy class should be simple (ie. animations). If the enemy object needs data it must not get it in your global Enemy object, you must provide the data from your main loop to the enemy object.

For example (pseudo-code):
Code:
class Engine {
  var enemies:Array;
  var bullets:Array;
  var player;
 
  function Engine() {
    createPlayer();
    createEnemies();
    stage.addEventListener(<keyboard and mouse events>); // safer to listen directly on stage
    addEventListener(Event.ENTER_FRAME, gameLoop); // will fire <fps> times per seconds
  }

  function gameLoop() {
    movePlayer();
    moveBullets();
    for each (var en:Enemy in enemies) {
      moveEnemy(en);
    }
    updateDisplay();
  }
 
  function moveEnemy(en:Enemy) {
    if (isHit(en)) en.die();
    else en.attack(player);
  }
  /*...*/
}


Wed Jan 05, 2011 1:42 pm
Profile WWW
Member

Joined: Mon Jan 03, 2011 11:35 pm
Posts: 6
Thank you for your answer.

Okaaay, interesting! That approach is a bit different from what I've done until now. I was told once to not have too many calculations those ENTER_FRAME loops, so I tried to split them up a bit, but maybe that was worse than having one big loop that handles everything instead?

Code:
stage.addEventListener(<keyboard and mouse events>);

I had all the control-related code inside the players's class. Maybe I should consider moving it?

Code:
for each (var en:Enemy in enemies) {

I'm only just starting to get what these for-each-in loops do and how they work. This is something I have to look up in my books...

Well, I guess there's only one thing to do; finish those books! (*_* ) I'm a bit bummed because I couldn't get my project to work entirely in FD this time, but it's okay, because I still love programming!


Wed Jan 05, 2011 2:53 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
You definitely /can/ have the keyboard/mouse listeners in the player if it doesn't lead to dependencies (like reading keyboard settings in a config file).

Having one big game loop is better than many ENTER_FRAME handlers.


Wed Jan 05, 2011 3:12 pm
Profile WWW
Member

Joined: Mon Jan 03, 2011 11:35 pm
Posts: 6
Quote:
Having one big game loop is better than many ENTER_FRAME handlers


Right, just as I expected :/

Thanks for all the help!


Thu Jan 06, 2011 3:32 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 45 posts ]  Go to page Previous  1, 2, 3

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.