View unanswered posts | View active topics



Reply to topic  [ 5 posts ] 
Error: Access of undefined property 
Author Message
Member

Joined: Sun Jul 13, 2008 9:32 am
Posts: 7
Reply with quote
Hi all:

First, let me say that FlashDevelop is amazing and I'm very thankful to the community for making it available.

Me, although I'm new to Flash/Flex development I've been a web developer using PHP/MySQL or ASP/SQL Server for almost 15 years so I'm no dev newbie.

The downside to FlashDevelop I'm learning is that it is very hard to find working examples on the web that target FlashDevelop; everything assumes either Flash or FlexBuilder. Sigh. Maybe FlashDevelop will become more popular and lots of people will be posting examples using it online!

Anyway, I've got a really stupid problem I can't get passed. All examples I can find seem to imply that use of a "id" attribute in MXML files provides access to the components via ActionScript, but every thing I try when I combine ActionScript with MXML gives me "Error: Access of undefined property." So I created this trivial example to illustrate my problem. My simple example uses a "Flex 3 Project" with only the one "Main.mxml" file containing the following, and I get the error "Access of undefined property btn." when I try to compile:
Code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Button id="btn" height="100" width="300" label="Click Me"/>
      <mx:Script>
         <![CDATA[
         btn.height = 200;
         ]]>
      </mx:Script>
</mx:Application>

Any help to tell me what I'm boneheadedly doing wrong will be greatly appreciated!


Sun Jul 13, 2008 9:44 am
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Post 
Thanks, FD is quite popular but examples are hard to find (and sometimes are really out of date).

There's some documentation being written but it mainly talks about Flash CS3 + FlashDevelop workflows:
http://flashdevelop.org/wikidocs/index. ... =Main_Page

In your example I guess the problem is that it isn't like HTML: I don't think the script tag is executed after the button is created, you must wait for the application proper initialization.
http://www.adobe.com/devnet/flex/quicks ... ionscript/

Other good thing to do in MXML is to write a "code behind" class for your MXML file - there's a nice sample here (and you'll see how it waits for application initialization):
http://www.flashdevelop.org/community/v ... 4469#14469


Sun Jul 13, 2008 11:56 am
Profile WWW
Member

Joined: Sun Jul 13, 2008 9:32 am
Posts: 7
Reply with quote
Post 
Thanks for the reply. Okay, I'm somewhat muddling through this. It seems that the "btn" is visible within a function, like this (I typed without actually verifying this compiles so if someone finds this who needs help let me know if it doesn't compile):

Code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp();">
      <mx:Button id="btn" height="100" width="300" label="Click Me"/>
      <mx:Script>
         <![CDATA[
          internal function initApp():void {
            btn.height = 200;
          }
         ]]>
      </mx:Script>
</mx:Application>


>> Other good thing to do in MXML is to write a "code behind" class for your MXML file

I actually just read a blog post with many comments that discussed how "code behind" was more of a curse than a blessing, and my past experience with ASP.NET leads me to concur... But I digress.

In your example I didn't see how he actually associated the code-behind file with the MXML file. Was there something missing from their example, like a "source" attribute?


Sun Jul 13, 2008 7:06 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Post 
Your sample code works perfectly fine - what exactly doesn't work for you?

Are you compiling using Flex 3 SDK (you should)?


Sun Jul 13, 2008 7:41 pm
Profile WWW
Member

Joined: Sun Jul 13, 2008 9:32 am
Posts: 7
Reply with quote
Philippe wrote:
Your sample code works perfectly fine - what exactly doesn't work for you?

Are you compiling using Flex 3 SDK (you should)?

Sorry if I wasn't clear.

What I was saying was that I solved the problem with the example I posted above and I was posting as a future favor to others who might find this thread while googling. That way they could actually see a working syntax example. (I always appreciate it whenever someone who asks a question on a forum follows up with an explicit answer with actual working syntax, so I was "paying it forward.")

My comment about non-working code meant that I had only done a "visual compile" and not actually tested the exact example in FlashDevelop before posting it (the machine I was on did not have FlashDevelop install for me to test.)

Is that clear? If yes, no need to reply...


Sun Jul 13, 2008 11:27 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.