PDA

View Full Version : I have problem with Flex 3(AS3,PHP,AMFPHP)


click
09-22-2009, 05:49 PM
I have problem with Flex 3(AS3,PHP,AMFPHP)..if someone is good and willing to help..please contact me

mail,msn,gtalk:mstanarevic@gmail.com
skype: mstanarevic

Thank you!

..it's hard to post and explain it here...but let's try

I am getting this error

TypeError: Error #1010: A term is undefined and has no properties.
at comp::SERVERS/founded()[C:\Users\click\Documents\Flex Builder 3\Bircuz-Gaming\src\comp\SERVERS.mxml:31]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.amfphp.callers::Server/_read()[C:\Users\click\Documents\Flex Builder 3\Bircuz-Gaming\src\com\amfphp\callers\Server.as:35]


with this code

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"
creationComplete="{init()}"
>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.core.Application;
import com.amfphp.callers.AMFPHPCaller;
import com.amfphp.callers.Server;
import com.amfphp.events.AMFPHPEvent;
import com.amfphp.events.AMFPHPErrorEvent;
import com.amfphp.AMFPHP;

public var caller:Server;
public var Object2:Object;
[Bindable]public var grid2:ArrayCollection;



public function init(...res):void
{
AMFPHP.GATEWAY = "http://localhost/amfphp/gateway.php";
caller = new Server();
caller.addEventListener(AMFPHPEvent.ITEMS_FONDED, founded);
caller.read();
}
public function founded(e:AMFPHPEvent):void
{
grid2 = new ArrayCollection(e.result.ServerInfo.InitialData);
}
]]>
</mx:Script>
<mx:DataGrid x="49" y="62"
id="grid"
dataProvider="{grid2}"
>
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="0"/>
<mx:DataGridColumn headerText="Column 2" dataField="1"/>
<mx:DataGridColumn headerText="Column 3" dataField="2"/>
</mx:columns>
</mx:DataGrid>

</mx:Canvas>


but when i change grid2 with object ..i get result but he is lost when function founded is finished i.e when it comes to this line (which goes right after function founded) dispatchEvent(new AMFPHPEvent(AMFPHPEvent.ITEMS_FONDED,false, false ,o));

and i get this error

Object2\r\n = <errors during evaluation>
No such variable: Object2


Any Ideas?
best regards and sorry for bad english

wvxvw
09-22-2009, 06:21 PM
Well, first of all, what's com.amfphp.*? Where did you get that... and why do you need that at all? Besides, you use very wrong naming for variables / methods - this makes it difficult to understand what is what. It is agreed that method should be camelcased and start with lowercase, same for the properties. Classes (including MXML) should be camelcased and start with the capital letter. Constants should be all uppercase, evey semantic part separated by underscore.
You should type "event" in the event handler, not "e", nor "evt". This is because of how MXML compiler parses XML, if you do that wrong, you will get errors compiling.

Now for the e.result.ServerInfo.InitialData part:
You're not casting that thing to anything, thus I cannot tell what can it be. But the only argument that ArrayCollection can accept is of Array type. If casting fails - this means that e.result.ServerInfo.InitialData is not an array.
What I would do:
- put the com.amfphp.* package at where it belongs, and that's definitelly not within the project ;) You're using framework classes, so, having additional classes for AMF is redundant. Use RemoteObject, or just don't use framework at all.
- Cast every property on the AMFPHPEvent#result to the expected type and see if it's not null. If it is null, then this would mean that serialization failed, and you will need to find out why. Most common reasons are:
- you're serializing custom class and you forgot to embed it in your project (i.e. you either don't import it at all, or import it, but never use).
- you mistyped the alias for the class when putting together the [RemoteClass] meta.
- you mistyped that alias in PHP mirroring class.
- you used some data in either PHP or AS class that cannot be serialized.
- you had arguments in constructor with no default values.

click
09-22-2009, 07:10 PM
.com and amfphp are folders in project (src) ...but thanks,i will try that..

wvxvw
09-22-2009, 08:30 PM
If they are folders in your project, then this should mean that you've written them, or the person who worked on the project before you. This is because amfphp.com (site) doesn't exist, it's amfphp.org. Regretfully, the development of this project (AMFPHP) was suspended. The developers didn't pass the rights for the project to anyone. So, whoever had written that code, he's not one of the off devs. Besides, AMFPHP never had any ActionScript library, only a few examples of how to use their code.

So, you're dealing with some custom code, and, it may not work just because it may be poorly written, and it's unlikely you'll find many other coders who used it as it wasnt publicly published... So, if you don't know what that is, you'll have to either learn it, or drop it and use the framework classes - at least you'll find some support with that.