//

YourPay some common errors and solutions

When working with YourPay service there some small issues you might run into and so I can remember in the future I am listing them here.

Fraud issue

If hit the server several times for testing you might be tempted to hit it with the same amount but remember that even though for you they are different hits, the store is receiving the same "client" hit so they will reject you request by marking it as a fraud.

Fraud Solution

Hit the server with different totals, even a minimum of 1 cent in difference between transactions is enough for you to get successful transactions with the store.

Store not able to process orders

One common issue is that when you hit the server from a page that is not registered with the application, YourPay will not recognize your store request and thus reject your request and it will break the whole experience.

Store not able to process orders solution

Always remember to change the location where YourPay is expecting your request, this could be easily forgotten when you are testing from different points on your servers or you are testing from Dev and then move everything to production.

Tags: , ,

//

Getting UPS Rates with PHP fixing small issue

There is an great class in Google Code written in PHP that works as a wrapper to the UPS API, I started using it about a year ago and never had issues with it since I was using it with Flash/AMFPHP/PHP, but now that I am working with a new shopping cart where I need this functionality but the front end is PHP only, I noticed that I was starting to get the following error:

PHP:
    Parse error: syntax error, unexpected $end in path.../UPSRate.php(131) : eval()'d code on line 1[php]

    After investigating the issue further I was able to fix the issue by only using eval on those elements where 'value' wasn't undefined.

    [php]if (isset($xml_elem['value'])) {
             $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
             eval($php_stmt);
    }

Notice that these parse errors do not break the application and that is why they weren't raising a flag in Flash but working on PHP alone we have to squash all these kind of warnings.

Tags:

//

Actionscript dispatch event fails and solution.

The Problem:

A event too close to the instantiation of an object is not being fired, I believe the speed of the code execution is too fast for the listener to be able to register for the event.

Lets take a look at the following class to understand the issue.

ActionScript:
    package application.views
    {

       import flash.display.Sprite;
       import flash.events.Event;

       public class TestView extends Sprite
       {
          
          public static const NAME : String = "TestView";
          public static const THE_EVENT : String = NAME + "The_Event";
          
          private var holder : Sprite;
          
          
          public function TestView ( )
          {
          
          init();
             

          }
          
          private function init () : void
          {
             holder = new Sprite;
             holder.graphics.beginFill(0x000000)
             holder.graphics.drawRoundRect(0, 0, 100, 100, 0);
             holder.graphics.endFill();
             addChild(holder);
             
             dispatchEvent ( new Event ( THE_EVENT))
          }
          
       }
       
    }

In the example above what we are doing is dispatching an event after the creation of a simple object. If you notice the call to the init function is right after the construction of this specific object, in this case the object that is listening for that specific event is never able to "hear" the event, although it has been fired.

Here is the construction of the TestView and the listening for the event:

ActionScript:
    private var testView : TestView;
    testView = new TestView;
    testView.addEventListener ( TestView.THE_EVENT, theEventHandler ) ;

    private function theEventHandler ( event : Event ) : void
    {
       trace("Event Fired");
    }

The Solution

The solution is very simple, add a delay as low as 1/1000 before the code execution.

ActionScript:
    package application.views
    {

       import flash.display.Sprite;
       import flash.events.Event;
       import flash.utils.setTimeout;

       public class TestView extends Sprite
       {
          
          public static const NAME : String = "TestView";
          public static const THE_EVENT : String = NAME + "The_Event";
          
          private var holder : Sprite;
          
          
          public function TestView ( )
          {
          
          //delay the execution of init by 1/1000
          setTimeout(init, 1);
          //init();
             

          }
          
          private function init () : void
          {
             holder = new Sprite;
             holder.graphics.beginFill(0x000000)
             holder.graphics.drawRoundRect(0, 0, 100, 100, 0);
             holder.graphics.endFill();
             addChild(holder);
             
             dispatchEvent ( new Event ( THE_EVENT))
          }
          
       }
       
    }

Conclusion

There are ways to go around this issue, that is for certain but being able to find where your problem is located at is important to provide the right solution at the right time. I am going to do some more research in regards to why this specific problem happens at a lower level but for now it allows me to trust that the listener is going to be able to "listen" for a specific event.

Am I happy with this solution? NO. but for this specific application I am working on I need to make sure all the elements are in place before continuing the chain of events rather than just trusting that items are drawn or attached on the display list.

//

SVN PROPFIND 405 Method Not Allowed

Problem

I was getting the following error after trying to update a SVN repository.

PHP:
    PROPFIND of '/': 405 Method Not Allowed

And had no idea what it meant. I read on the internet that could be from trying to checkout a file that is none existent. The interesting thing is that I was just doing an update (svn update).

Solution:

PHP:
    svn cleanup

That solved my problem immediately. After running the cleanup command I was able to make my update.

Tags: ,

//

Learning PureMVC from HydraMVC

Intro

This post is not specifically on how to learn everything about PureMVC with HydraMVC but mainly points out their notification workflow document that they have on their site and some other statements they make on their site.

Keep in mind that HydraMVC is a complete rewrite from PureMVC, made specifically for the Flex framework.

HydraMVC Notification Workflow

Beautiful (technically speaking) document that allows you to follow their notification system from beginning to end (tip: start from the view component and follow along).

Screenshot:

Direct link to original PDF file in HydraMVC website (full resolution).

Briefly about HydraMVC

If you are using PureMVC keep in mind the following.

PureMVC intends to be language-agnostic where HydraMVC is a compromise by design

Meaning that the team at HydraMVC took the time to make the framework beautiful to fit their needs within Flex framework while PureMVC has kept it open so that you can extend to other languages such as PHP, Javascript, Objective C, Ruby and more. This gives PureMVC the room to breath without having to be tied up to a specific language.

But in the end that doesn't mean that we can't learn from HydraMVC if you are working on PureMVC, specially since Hydra is based (and complete rewrite) from PureMVC.

Hydra Events and Implementation

In addition to using Events vs. an independent Observer pattern, HydraMVC also streamlines implementation, encapsulating much of the initialization code that needed to be written when implementing PureMVC.

I am familiar with Flex and have written couple test applications with the framework but I haven't used HydraMVC with Flex but I am curios on their initialization code which for the sound of their statements you have to write less code while still keeping the same functionality.

Here are some useful links:
PureMVC
HydraMVC

//

Send multiple parameters to event handlers

At one point or another during the time you write applications with ActionScript 3 you will have to send parameters from to an event handler. By default you can't send information unless you use the DataEvent, but that only allows you to send a string. That is OK if that is all you need to send but how about multiple parameters? How about an object or references?

In the example below we create a square on the stage that then will dispatch a custom event with 3 parameters (two strings and one number).

ActionScript:
    package {

     import flash.display.Sprite;
     import event.CustomEvent;
     import flash.events.Event;
     import flash.events.MouseEvent;

     public class App extends Sprite
     {

       var square : Sprite ;   

       public function App()
       {
          init ( ) ;
       }

       private function init ( ) : void
       {

        //add the event listener to the Document class.

       this.addEventListener(
            CustomEvent.MOUSE_CLICK,
            customEventHandler  ) ;           

        // Draw a square on stage and add a mouseEvent
        // that then will dispatch a custom event

        square = drawSquare();
        square.buttonMode = true;
        square.addEventListener (
        MouseEvent.CLICK,dispatchCustomEvent ) ;

        addChild(square);

        }

        private function dispatchCustomEvent ( e : Event ) : void
        {
        dispatchEvent ( new CustomEvent (
                            CustomEvent.MOUSE_CLICK ,
                            "myParam1",
                            "myParam2",
                            3 ) ) ;
        }

        private function customEventHandler ( e :CustomEvent )
        {
            trace( "Param 1: " + e.param1 ) ;
            trace( "Param 1: " + e.param2 ) ;
            trace( "Param 1: " + e.param3 ) ;
            }

        private function drawSquare ( ) : Sprite
        {

            var square:Sprite = new Sprite();

                square.graphics.beginFill(0x000000);
                square.graphics.drawRect(100, 100, 100, 100);
                square.graphics.endFill(); 
                return square as Sprite; 
             }

        }

    }

Custom Class

ActionScript:
    package event
    {   

     import flash.events.Event;

     public class CustomEvent extends Event
     {

        public static const MOUSE_CLICK : String = "mouseClick";

        public var param1 : String ;
        public var param2 : String ;
        public var param3 : int ;

        public function CustomEvent(
                            type : String, 
                            param1 : String,
                            param2 : String,
                            param3 : int,
                            bubbles:Boolean = false,
                            cancelable:Boolean = false )
        {

            super ( type, bubbles, cancelable ) ;

            this.param1 = param1;
            this.param2 = param2;
            this.param3 = param3;

         }

         override public function clone(  ): Event
            {
                return new CustomEvent( type, param1, param2, param3,
    bubbles, cancelable );
            }   
     }
    }

//

Project 10th to the 100th from Google

Last fall Google launched project 10^100 where they requested ideas from the public to make them reality... well not all of them, after the ideas were submitted they selected the top 16 ideas they liked and now they are asking the public to select the final 5 ideas that they are going to help be a reality.

My favorite idea:

Create genocide monitoring and alert system:

Build and refine tools capable of disseminating genocide-related mapping and related information in order to save lives. Much of the necessary technology and data-gathering methodology already exists both for general crisis mapping and for early warning systems capable of preventing mass atrocities. A key remaining step is to make this data more widely available to strengthen international aid agency coordination, improve resource allocation, develop timely policy and help evaluate current humanitarian practices.

I believe having a service such as this will help all of us the severity of the problem. Because we sit at our desks for 8 hours a day and then relax at home it is easy to forget that issues as genocide exist and what a better way to use Technology to do so. Twitter anyone?

It will be interesting to see how far these ideas will go and which will become a reality.

http://www.project10tothe100.com/vote.html

//

IF statement in programming

I don't know about the programming language you are dealing with but I would say that most of them will handle the IF statement in the same way and it has always bothered me. Specially when there seems to be no way to avoid using it for a specific circumstance.

For example lets say you want to run a set of actions depending on the value of a variable:

ActionScript:
    if (variable == true) {
       //then to all this
    }

I am trying to figure out a way to avoid this set up specially when you are re-using a set of functions but you always have to test for the value of a variable.

Another example would be a game, if for example you have 1000 units and all of them will have a state of "sit" or "standing" given their "position" property. Now you have a 1000 units that will be testing "if they are sitting or standing". I know this issue can be solved with the set up of the application rather than the IF statement but it is to give a clearer example of the issue.

Lastly I think it bothers me the most with Singletons. Most of the singletons you have to test for a property to define if you are going to create a new instance of the Singleton or if you just going to use the current instance.

How much overhead is this for the processor? Minimum? Nothing? I am assuming its almost nothing and that is why Singletons are so popular, althought we know some people believe that Singletons are _root in ActionScript which make more damage than helping. But that is besides the point.

If you have some ideas on how to improve the use of the IF statement let me know.

//

Brendan Lee talks with Cliff Hall (pureMVC)

Brendan Lee takes the time to talk to Cliff Hall

Tags:

//

How long does it takes you to get ready for something?

Does getting ready to get things done get in the way of getting stuff done? Although this video emphasizes procrastination I would say that the person represented in the video was getting things done, but not the things that were supposed to get done.

Next time you start a new task ask yourself, Is this really going to help me accomplish my original goal?

Enjoy!

Tags: