Archive for category Frameworks

Book review: Flex 3 with Java

Book review: Flex 3 with Java (follow link to buy)
ISBN: 1847195342
ISBN: 13 978-1-847195-34-0
Publisher: Packt Publishing
Author: Satish Kore

Flex 3 with Java Cover

Flex 3 with Java Cover

Short version: If you are a Java / PHP developer seeking to get started with Flex, building on your skills as a server-side developer, this book will do you good. If you are new to software development, or just started out I would recommend you check out Essential ActionScript 3.0 by Colin Mook, then come back to this book when you have some experience doing applications with AS3.

Slightly longer version: Some time ago I reviewed Mastering phpMyAdmin 3.1 from Packt Publishing, and since they had some interesting books on Flash / Flex I volunteered to review a few more.
First out is Flex 3 with Java. It’s a 300 page book, dealing with Flex, Java and how you can build solutions using BlazeDS as a backend.
I first checked out Flex back when the Flex 3 beta came out. At that time I was doing PHP with the Prado Framework, and instantly felt like home within the Flex IDE. However, I never took the time to really get into Flex, and my knowledge of ActionScript was pretty limited at the time.
I’ve now been working with AS3 for six months, and I’ve got a pretty solid grip on it. Most of the work I’m doing is pure AS3 (no Flash IDE, no Flex SDK), but I’ve got some very interesting side-projects built on Flex in the works as well.

The book assumes you have no experience with Flex / Actionscript from earlier. Now, it is clearly written for a more tech-savvy audience. You do not need to be a experienced developer to follow the subjects covered, but it will most certainly help to have done some software development before picking it up. The author gets a bit ahead of himself on some topics in the book, but it’s not a big problem. However, I would have liked to see a “who is this book for” section at the beginning, stating that this books is well suited for developers wanting to pick up Flex.
As expected it spends the first few chapters dealing with installation on the Flex SDK / tools as well as a brief but good coverage of AS3 and the basics of MXML.

Going into this book I was expecting the majority of the contents to cover the actual interop between Java and Flex. The book clearly deals with much more than that. Given that I’ve been trough a number of Flex and AS3 books the last months I think I would have preferred a book that was focusing more of it’s energy on the core subject instead of peripheral topics such as styling, packaging and deployment and i18n support. I totally agree that these subjects are important to master, but I think it would have been better if the book focused more on the actual interops topics as mentioned above. For me the books falls a bit between two chairs, as it does not spend enough time on basics to give the complete beginner a deep enough intro to Flex and AS3, yet not enough on the heavier side for the more experienced developer.

Oh, the book is also available as PDF if you prefer that.

Download Chapter 5 – Working with XML

PS: Check back soon as I will have a review of Papervision3D Essentials ready!

, ,

1 Comment

Book preview: Papervision3D Essentials and Flex 3 with Java

Following my review of Mastering phpMyAdmin 3.1 Packt Publishing was kind enough to send me a couple of more books to review. While I am waiting for these books to get here I have gotten my hands on some sample chapters. Check them out!

Papervision3D Essentials

Papervision3D Essentials Cover

Papervision3D Essentials Cover


Authors
Jeff Winder, Paul Tondeur
ISBN
1847195725
ISBN 13: 978-1-847195-72-2

Download Chapter 8 – External models











Flex 3 with Java

Flex 3 with Java Cover

Flex 3 with Java Cover

Author Satish Kore
ISBN 1847195342
ISBN 13 978-1-847195-34-0

Download Chapter 5 – Working with XML











, ,

No Comments

XNA Platformer Starter Kit – Falling Apples

As I mentioned in this previous post I’ve started to play around with C# and XNA Game Studio, and it’s very entertaining. I started out using The Platformer Starter Kit , which is a basic platformer game that you can customize and base your game on. I followed the tutorials mentioned in the previous link, and everything just works pretty smooth. Very satisfying to see immediate results reflected in a working game. After finishing them I decided to add a new feature by myself, a falling apple which would kill the player (I’ve been playing I Wanna Be The Guy lately). Hence, this post: XNA Platformer Starter Kit – Falling Apples. Now, this is a very basic feature. I just based my Apple on a copy of the Gem class, and did some minor modifications to allow them to fall down once the player walks under them, and if the player is hit he’ll die. A picture to show the final result:

Falling Apples

Falling Apples

Please bear in mind that this post is just a note of the changes I did to make this work, and should not be considered a full tutorial. I might end up doing more proper posts on XNA as I progress in my work with it.

So, here it goes!

First, create a new C# class. Just copy all the contents from the Gem class, and rename Gem to Apple (and gems to apples). Also, add the following line to the Apple constructor so that we can see the difference between apples and gems: Color = Color.Red;

Now, remove the following lines, since we do not need them:

private SoundEffect collectedSound;
 
public readonly int PointValue;

And add these:

private const float GravityAcceleration = 6500.0f;
private const float MaxFallSpeed = 600.0f;
private bool isFalling;
 
public Vector2 Velocity
{
    get { return velocity; }
    set { velocity = value; }
}
Vector2 velocity;

Now, since we want to be able to trigger the apples to fall when the player passes under them, we’ll need to create a bounding rectangle, which is taller than the actual apple. This will be the rectangle the player will collide with once he passes under the apple, and hence the apple will start falling.

public Rectangle TriggerRectangle
{
    get
    {
        int left = (int)basePosition.X;
        int width = 32;
        int top = (int)basePosition.Y;
        int height = 200;
        return new Rectangle(left, top, width, height);
    }
}

We need to implement some kind of basic physics to calculate how fast the apple should be falling. This is done by adding a new method called ApplyPhysics, which checks if the apple is falling, and if it is, it updates the velocity and position based on some simple calculations:

private void ApplyPhysics(GameTime gameTime)
{
    float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
    if (isFalling)
    {
        velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed);
        Position += velocity * elapsed;
    }
}

To make sure it actually falls when triggered we need to update public void Update(GameTime gameTime) and add a call to the ApplyPhysics method we just created. The call can be added right after bounce, at the end of the method:

    bounce = (float)Math.Sin(t) * BounceHeight * texture.Height;
    ApplyPhysics(gameTime);
}

The last thing we need to do in the Apple class is to add a method for actually starting the fall:

public void OnRockFalling()
{
    isFalling = true;
}

Next up are some changes to the Level class. Find the line which creates the Gem array:

private List<Gem> gems = new List<Gem>();

And add a new array for the Apples:

private List<Apple> apples = new List<Apple>();

Next up is the loading of the Apples. In the LoadTile method, add a new case statement as follows:

    case 'R':
        return LoadAppleTile(x, y);

This will load R’s in the level code as apples. We now need to create the LoadAppleTile method:

private Tile LoadApppleTile(int x, int y)
{
    Point position = GetBounds(x, y).Center;
    apples.Add(new Apple(this, new Vector2(position.X, position.Y)));
    return new Tile(null, TileCollision.Passable);
}

Almost there! We need to create a few news method for getting the apples to work. The first is called UpdateApples, which checks the collisions with the player:

private void UpdateApples(GameTime gameTime)
{
    for (int i = 0; i < apples.Count; ++i)
    {
        Apple apple = apples[i];
        apple.Update(gameTime);
        if (apple.BoundingCircle.Intersects(Player.BoundingRectangle))
        {
            OnPlayerKilled(null);
        }
        else if (apple.TriggerRectangle.Intersects(Player.BoundingRectangle))
        {
            OnAppleFalling(apple);
        }
    }
}

Next up is the OnAppleFalling method, which in turn calls OnAppleFalling in the Apple class.

private void OnAppleFalling(Apple apple)
{
    apple.OnAppleFalling();
}

Now we just need to insert calls for these methods in the correct places. First up is the UpdateApples method. This is called from the Update method. Just find the following line:

    UpdateGems(gameTime);

and insert the UpdateApples call under it:

    UpdateApples(gameTime);

The last change is to the Draw method. You’ll see there is two lines used to draw the gems, and that’s what we need to do for our apples. Insert the two following lines after the code for the gems:

foreach (Apple apple in apples)
    apple.Draw(gameTime, spriteBatch);

Now, to give this a spin, open the 0.txt level file and place some R’s here and there. When you start up the game you should see some red gems which falls down when you pass under them.

PS: A more clever approach here would be to create a base class for these classes, which would hold all the shared logic and methods, but the goal for this tutorial is to show how to implement the new feature as easily as possible.

Technorati Tags: , ,

, ,

4 Comments

Blog refresh, playing with XNA Game Studio

So, I finally got around to upgrading Wordpress and setting up a proper theme. I still want to customize it a bit, but it’s fine for now.

I’ve recently started playing with XNA Game Studio, and I’m really impressed with what Microsoft has pulled off with this framework. I found a starter-kit for a platformer, and I was up and running, making new content and features in less than 45 mins. It’s been a long time since I last worked with C#, and I found it refreshing to get back to it.  I’ll try to do some posts on it later on.

No Comments

Getting back to business!

I’ve been dormant for quite some time, mainly due to a major project going on at work. This week I’m starting my vacation, and its time to get back to all things fun. Today I got offered a spot on the Prado Developer Team, which I hope will prove to be both a challenge and a great opportunity to improve my knowledge on both the framework and PHP.

As a part-time project I’ve started building a multi-touch display surface inspired by Microsoft Surface. I’ve completed a *very* basic edition (tutorial here, and I’ve just started planning a more complicated setup along the lines of this project.

I’ll do some posts on the process as soon as I get some pictures.

Technorati Tags: , ,

   

2 Comments

VCL/PHP followup


After receiving quite some feedback on my post “Why Delphi for PHP should have used Prado instead of VCL” I decided to do a follow up to that post. Some of the feedback was quite interesting, hence this post was born.

First and foremost I’d like to address the feedback I got regarding the class name prefixing in VCL/PHP. I argued that the lack of class prefixes could create problems in the future, and used Prado’s T notation as as sample of something that would at least be a bit better. Let’s take a look at two VCL/PHP classes named Collection and Object. These two names are often reserved in programming langues (atleast object oriented ones). If PHP decides to introduce these two classes the VCL/PHP guys would be pretty screwed. It would involve refactoring the framework as well as applications which uses those classes. Prado on the other hand has a prefix (TCollection etc. minor, but it’s a world of difference). I assume that the VCL/PHP authors will introduce namespace support with PHP 5.3, so this issue will hopefully be a thing of the past when 5.3 ships. That said, I’m a bit curious to see how the migration / backwards compability would turn out if VCL/PHP adopt namespaces.

What I miss in the feedback I got from my previous post was people acually using VCL/PHP for enterprise applications and how that is working. From what I can tell the usage of Exceptions is still limited to the 3rd party libs such as Zend Framework which are included with VCL/PHP. That’s a bit interesting.

I’d like to touch on the comment made by Pieter Viljoen for my original post. I agree that Codegear pushed quite a toolset for the PHP community in a short time, but the underlying code is not enterprise quality. One can argue that PHP is ugly and flawed (not sure I agree on that part), but that does not mean that one should not strive for good architecture and methodology when developing frameworks on top of PHP. I see the point that VCL/PJP offers features that are interesting for starting PHP developers, but for large scale applications I just don’t see it. I’d be pretty cautious pulling in a framework without exception support if I was to create an application.

Again, I’m really interested in some feedback from someone that actually has built applications with VCL/PHP.

I’ve also noticed that there is not much activity in the VCL/PHP SVN repository. Anyone know what’s going on there?

Technorati Tags: , ,

  

2 Comments

Populate PDF templates with PHP / FPDF / FPDI


Ever wanted to generated PDF documents on the fly with PHP? Perhaps populate a standard contract with a customers name and address? FPDF and FPDI are two neat libraries which greatly helps when working with PDF files. FPDF is the main library for handling PDF files, while FPDI lets your import existing PDF documents into the FPDF documents. In the code sample I’ve prepared here I’m importing a PDF template document, writing some information to the document, then sending it to the “customer”. FPDF offers several neat ways to expose the generated document, such as a stream to the browser, a string, or just storing it to file. You can download PDF Sample code to test it.

Be sure to head on over to the FPDF site and FPDI site for more information on these two libs.

Related posts:
Generated PDFs over HTTPS with Internet Explorer

Technorati Tags: , ,

10 Comments

Prado Framework 3.1.2 released


My favorite PHP framework just got a new release, adding several new components and fixing 30-ish bugs. The bundled JavaScript libs (Prototype / script.aculo.us) have also been upgraded, so that should help lots of people struggling with the old versions. Head on over to PradoSoft.com to download the new version. If you are new to Prado, I recommend checking out the Prado QuickStart tutorial.

Technorati Tags: , ,

2 Comments

Why Delphi for PHP should have used Prado instead of VCL

I recently went to a presentation where some guys from CodeGear showcased Delphi for PHP and VCL4PHP. It’s a new product which enables PHP developers to use drag / drop and wysiwyg methods to build applications with PHP. The IDE uses VCL4PHP as the underlying framework.

This kind of tool is something that ASP.net has had for a long time (ie Visual Studio.net). Not only does it make the development process easier when it comes to building applications, but it also handles setup of applications, default configs etc. Until now there hasn’t been any tools for doing this with PHP, so I sincerely congratulate CodeGear on getting something out to the masses. Their IDE is a really nice tool with lots of potential. It ships with apache, and has lots of nice features like a integrated debugger etc. The immediate draw-back is that it runs on Windows only. My impression is that most PHP developers (atleast above hobby level) works on Linux based workstations, so I imagine getting a strong user base could prove to be difficult.

Now, why do I think that Prado is far superior to VCL, and why would it have been a better choice:

1.Exception handling
Any framework which are viable for larger scale application development should use exceptions. It’s an established way of controlling code flow and making sure the code can recover from error.

VCL: This is the first MAJOR flaw which would possibly be the hardest to fix. I’ve spent some time looking around in the VCL code, and there is some basic exception handling here and there. The problem is that most of the controls does not have any exception handling at all. This makes it very hard and tedious to control the follow when errors occur.

Prado: Usage of exceptions throughout the whole framework, with the possibility to have custom exception handlers lays the foundation implementing proper flows in the application and user friendly feedback when errors occur.

2. Usage with other PHP frameworks
A framework needs to play nice with other framework these days. There is no framework that has everything, so the coder will most likely use any given framework in addition to something else.

VCL: None of the controls I’ve seen while checking out the VCL source code are prefixed. Having controls with class names like ListView, PageControl, TreeNode etc won’t play nice with other frameworks. Also, using class names like Object and Component isn’t something you’d want to have in a framework.

Prado: All components in Prado are prefixed with a ‘T’ like TLabel, TPage, TListView ensures cooperation with other frameworks.

3. Generation of HTML code from controls
VCL: The controls implement a method called dumpContents which basically writes HTML and JavaScript tags and attributes by using echo. Some sub classing is done where the parent renders as well.

The following snip is taken from their CustomLabel code:
552 if (trim($this->LinkTarget)!=”") $target=”target=\”$this->LinkTarget\”";
553
554 $class = ($this->Style != “”) ? “class=\”$this->StyleClass\”" : “”;
555
556 echo “<div id=\”$this->_name\” $style $alignment $hint $class”;
557
558 if ($this->_link==”") echo “$events”;
559
560 echo “>”;
561
562 if ($this->_link != “”) echo “<A href=\”$this->_link\” $target

By letting most of the controls be responsible for writing the low-level HTML code it’s much harder to keep the code XHTML valid, and does not exactly scream re-use. See next point for how Prado handles this.

Prado: Controls that render contents in Prado extends TWebControl. I’d like to quote the Prado manual for TWebControl here:
“TWebControl is the base class for controls that share a common set of UI-related properties and methods. TWebControl-derived controls are usually associated with HTML tags. They thus have tag name, attributes and body contents. You can override getTagName to specify the tag name, addAttributesToRender to specify the attributes to be rendered, and renderContents to customize the body content rendering. TWebControl encapsulates a set of properties related with CSS style fields, such as BackColor, BorderWidth, etc.

Subclasses of TWebControl typically needs to override addAttributesToRender and renderContents. The former is used to render the attributes of the HTML tag associated with the control, while the latter is to render the body contents enclosed within the HTML tag.”

4. XHTML code generation
Producing valid XHTML is something we should all strive to do. Not doing so may result in display problems in most browsers.

VCL: I tried to validate a basic demo site created with Delphi for PHP and VCL4PHP. The results speaks for them selves. The generated HTML code is not XHTML compliant. Example from the CustomLabel code again – echo “<A href=\”$this->_link\” $target. Remember that XHTML tags are always lowecase. There are several other problems as well, and the validation link shows some of them.

Prado: The HTML code that Prado generates is mainly done in the parent controls, so keeping the base implementations XHTML valid mostly ensures that the child controls will be as well. This also removes the actual rendering code from the controls, so creating new controls is far easier and cleaner.

5. Validation controls
Input validation is some of the most boring tasks when writing web applications, and it can be fairly difficult to get it right.

VCL: According to the guy from the presentation there is none, but I found a screen cast here. It seems way more tedious than the Prado way, and I can’t tell if it’s released or just in trunk / testing at the moment.

Prado: Prado ship with several validation controls which works both client side and server side. TRequiredFieldValidator, TRegularExpressionValidator and TEmailAddressValidator ensure that the coder can feel very safe when it comes to validating input. TCustomValidator lets the user create custom validation logic to perform tasks (for example login checks). A complete list and usage examples can be found here.

6. Encapsulation
Encapsulation is a way to make sure that the internal state of classes isn’t messed with by code that should not be able to.

VCL: I’ve been looking trough the code trying to find controls that actually use private methods for managing their internals. As far as I can see there is only a fraction of the controls which uses private methods, and when they do it’s only for one or two methods. This is a design no-no when everyone can call everything.

Prado: Only methods which have to be public are public. This ensures proper encapsulation and prevents the coder from accidentally messing up the state of a control.

7. Component properties

VCL: Delphi for PHP stores all component properties in XML files. I see the point of doing this for the sake of the IDE, but when it comes to runtime code I do not. During the demo they showcased how to use smarty templates with VCL, and to add a control which was created in the RAD gui they use markup ala {button1}.

Prado: Prado separates the code and login into two files (.php which holds the page class, and .page which holds the markup). The properties for the components are kept in the .page files which is a much easier way to look at the controls when creating markup. Check this link for a quick intro to how Prado handles this.

8. Usage of globals
VCL: Using globals? We all know this is bad and belongs pretty much belongs in PHP4 applications. If you need a dirty hack it can be a last resort kind of thing, but using it throughout the whole framework?

Example of globals usage:
30 $exceptions_enabled=true;
31
32 global $use_html_entity_decode;
33
34 $use_html_entity_decode=true;
35
36 global $output_enabled;
37
38 $output_enabled=true;
39
40 global $checkduplicatenames;
41
42 $checkduplicatenames=true;

183
184 /**
185 * Global $application variable
186 */
187 $application=new Application(null);
188 $application->Name=”vclapp”;
189

These things should be config related and stored in either the application object or a core base class.

I also checked out the blog demo from this page, and usage of globals can be found throughout the applications (global $BlogDB, global $AdminDeleteComment etc).

Prado:
Prado uses globals in one single file, and that’s the file responsible for generating client side scripts. Settings which span the whole application can usually be accessed from the application object.

9. Ajax

I’m considering to do another post comparing the ajax features in depth, but I just wanted to point out one thing seen in this screencast on AJAX. The coder escapes from PHP to write the javascript, then jumps back into PHP. In Prado things like these follow the same design as the rest of the framework.

Conclusion

I want to do some more in depth comparisons of controls and ajax support later on, but my current impression of VCL4PHP is that it’s “out of date” or not quite on a professional level. Not taking advantage of PHP5 features like interfaces and encapsulation, lacking proper exception handling, key features like validation and not generating valid XHTML code are all major points which I would expect a proper framework to have in place. One has to wonder why CodeGear went in this direction.

If you consider using VCL / Delphi for PHP I recommend that you first stop by the VCL4PHP forums to get some impressions on how people are using it and see their experiences.

I would really like to come in contact with someone that knows VCL4PHP so that a in depth comparison of the different controls can be done.

24 Comments

Custom active controls in Prado Part II

We’ve been working on getting drag-drop features to work in Prado for a while now, and we got it on a level which fills our needs.

The current state lets you register drags, drops and drag-drop. The most annoying limitation we have at the moment is that you only get the drop container on callback. We currently slip around that by sending our data with the callback parameters.

The demo attached here shows dragsdrops (green), drags (yellow) and drops (blue). When an element is dropped the label is updated with the name of the drop element and the callback parameter data. The callback data is currently set up in the js file and it’s only set for the dragdrop elements, but there should be nicer ways to do this.

The component only uses javascript that ships with Prado, so no external libs are required. The actual MyDraggable php class is based on another Prado component, and it probably needs some cleanup as well. The demo ships with Prado 3.1, so just unzip and set correct permissions.

Kudos goes to my co-worker Lars-Olav for getting the client side stuff to work. Javascript is not my strong side ;)

Online demo – http://prado.eirikhoem.net/dragdropdemo/www/
Download source – http://www.eirikhoem.net/dragdropdemo.tar.gz

Update: Source file is not up to date. Will fix asap.

No Comments