views:

74

answers:

1
package samples.flexstore
{

import flash.events.Event;

public class ProductThumbEvent extends Event
{
    public static const DETAILS:String = "details";
    public static const BROWSE:String = "browse";

    public var product:Product;

    public function ProductThumbEvent(type:String, product:Product)
    {
        super(type);
        this.product = product;
    }

    override public function clone():Event
    {
        return new ProductThumbEvent(type, product);
    }
}

}

I need to know these things for better understanding.

What is public static const DETAILS:String = "details";

Why static keyword is used. Why const used and what is it for. Why does the DETAILS:String have a value details.

public var product:Product;

    public function ProductThumbEvent(type:String, product:Product)
    {
        super(type);
        this.product = product;
    }

What does this constructor do? What does super(type) do? what does this.product = product implies?

override public function clone():Event
    {
        return new ProductThumbEvent(type, product);
    }

What are they trying to return why can't they return in previous constructor instead of creating a clone of the above method.

Thanks.

+1  A: 

You are asking some pretty basic questions. I would recommend going through some basic programming courses to get you started, but here are the answers to what you asked.

public static const DETAILS:String = "details";

This means declare a string that is unchangable called DETAILS that may be accessed outside my class, and without instantiating an instance first.

Static means the member can be accessed without an instance of the class being created. so ProductThumbEvent.DETAILS is how you would access the static member DETAILS in your code.

const says that the value "details" assigned to DETAILS is constant and can not be changed.

super(type) says to call the base class (Events) constructor and pass type to it.

this.product = product says take the value passed into the product parameter and assign it to public member Product.

The purpose of the clone method is to return a new instance of the object. One could just as easily call the same constructor again if they chose (assuming they still have the proper argument data in scope), but the original author has decided to implement this method to do the task.

Matthew Vines
Thanks a lot for your time and such clear explanation.