Friday, 9 March 2012

Flex, Image component cannot load the picture

Problem
adobe flex AS3.0, error, Flash player v11.
problem, the Image component cannot load the picture file (jpg in precise), the swf is loaded, can load data from php but cannot load images
very rare problem, found on firefox on mac while on the same machine the safari was working without any problem at all!!!

Solution
You must create the crossdomain.xml in the root directory of your site, defining the domain where that flash belongs.

Syntax of crossdomain.xml

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
  SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">

  <cross-domain-policy>
    <allow-access-from domain="www.mycompany.com" />
    <allow-access-from domain="mycompany.com" />

  </cross-domain-policy>

Thursday, 13 October 2011

how to adjust the volume in Sound object

//define somewhere in your class
private var soundPinkPanther:Sound, soundChannelPinkPanther:SoundChannel;

//load the sound
    soundPinkPanther = new Sound(new URLRequest("audio/PinkPanther.mp3"));
//start to play
    soundChannelPinkPanther=soundPinkPanther.play(0,10);   //start immidiatelly

//turn off the volume
    soundChannelPinkPanther.soundTransform=new SoundTransform(0,0);
//turn it on again
    soundChannelPinkPanther.soundTransform=new SoundTransform(1,0);
//turn it on at middle volume
    soundChannelPinkPanther.soundTransform=new SoundTransform(0.5,0);


In this example, in order to adjust volume I am creating a new SoundTransform object and I assign it to soundChannelPinkPanther.soundTransform. There is no other way :( this way I taken from adobe's (complex example).

If you try something like this
soundChannelPinkPanther.soundTransform.Volume=0 
your will take no effect.

This strange way in order to change the volume, doesn't meet the know OOP way. I hope in future Adobe correct this strange things...

Wednesday, 13 July 2011

The mouse wheel scroll with VGroup and Scroller is not smooth and it jumps abnormal points

adobe flex4.0 AS3.0


This is happening when you have photos in the VGroup, the Scroller jumps the photos each time in order to be viewed whole and not cut. This sometimes is not working well or we don’t want it.

What we have to do is to get the mousewheel event and calculate by our own the vertical scroll position.

1. implement the event like above:

protected function scroller1_mouseWheelHandler(event:MouseEvent):void{
  //calculate the new position 
  vgroup.verticalScrollPosition+=(event.delta*-20);            
  //stop the event’s bubbling
  event.stopPropagation();
}

2. add the event listener by your own! Because we want to get it before calculate the vertical scroll position. In event’s world… "we want to capture it", and this could be done only is we add the listener by our own, note the underlined true argument, so do:

scroller.addEventListener(MouseEvent.MOUSE_WHEEL,scroller1_mouseWheelHandler,true);

That's all

Tuesday, 5 July 2011

How to make visible the comments of your own function, on insight feature pressing the dot, as help of the function


With this way you may give help to the object user about how your function works.

Simply put your remarked text with /** */ above of the function. Do not use /* */ or //, only /** */ you should use for this usage.


/**x is the X coordinate and y is the Y coordinate of the image*/
//TODO: this function might have a bug… I have to check if the image is null!
public function locatePictureAt(x:int,y:int):void{
                image.x=x;image.y=y;
}

In Flex IDE, when you will press the dot to go to the specific function, it will show as help of this function the text placed in /** */. The “TODO” text will be not appered, either if it was placed in /* */.

Monday, 4 July 2011

required steps in order to dispatch your own events

problem

adobe flex AS3.0
required steps in order to dispatch events
good luck :)
---
> page dennis
difficulty level

5/10 :)
compatibility

step1
the class where dispatch event, should extends the EventDispatcher object
example: public class MDlogin extends EventDispatcher

step2
create some (stupit) public strings… where will be the events (id)
example:public var Event_LoginSuccess:String='Event_LoginSuccess';

step3
in order to dispatch an event call the dispatchEvent method (where is coming from EventDispatcher)
example: dispatchEvent(new Event(Event_LoginSuccess));

step4
create your own custom Event object where will be dispatched.
The Listeners, should get your Event object and not the Flex’s Event, in order the Listener to be able to get the additional public variables and functions of your custom events!
- create a new Actionscript Class (file and so on) that extends the flash.events.Event class
- add you public variables and functions where will be available for the listener (do not make it have, instead, give easily a reference of the object where dispatch the event)

Conclusion
An Event object is nothing more than a silly object that is useful because the runtimer can dispatch it! It is nothing more! It is a cabinet that can gives ready information to the listener (some public variables or much better only getters).
If Flex’s world and in general OOP’s world, the Events are the only professional communication way between different and maybe unknown objects.

Wednesday, 29 June 2011

how to change the frame rate of the flash player on runtime (from inside your code)

it is not so easy as you think!

to set it 60 call:

Object(FlexGlobals.topLevelApplication).stage.frameRate=60;

or... create this setter
public static function set frameRate(framerate:int):void{
    Object(FlexGlobals.topLevelApplication).stage.frameRate=framerate;
}
and call
frameRate=60;

you may also define it in mxml 
frameRate="60"

The default value of the player is 25; increasing the frame rates you consume more cpu! don't forget that you application will run in a slower computer than yours!

Tuesday, 21 June 2011

how to bringToFront an object on a container?

situation

How to bring to front an object of the same container front of someone else (of the same container)? The easiest wait it to change the “depth” property of to object. WRONG! In the meanwhile it should work!
problem

adobe flex AS3.0, 
how to bringToFront an object on a container?
The depth… doesn't matter!
---
> dn

difficulty level

3/10 :|
compatibility

flex 4.0
solution

public static function bringToFrontWithApplicationHost(container:Application,displayObjectToBringToFront:IVisualElement):void{
   container.swapElements(container.getElementAt(container.numElements-1),displayObjectToBringToFront);
  }
  public static function bringToFrontHostWithContainerHost(container:Container,displayObjectToBringToFront:IVisualElement):void{
   container.swapElements(container.getElementAt(container.numElements-1),displayObjectToBringToFront);
  }

or use what ever you want... they do the same

  public static function bringToFrontWithApplicationHost2(container:Application,displayObjectToBringToFront:IVisualElement):void{
   container.removeElement(displayObjectToBringToFront);container.addElement(displayObjectToBringToFront);
  }
  public static function bringToFrontHostWithContainerHost2(container:Container,displayObjectToBringToFront:IVisualElement):void{
   container.removeElement(displayObjectToBringToFront);container.addElement(displayObjectToBringToFront);
  }