I recently had a problem that I thought would be pertinent to the FlashCoders 
group.  Thanks to JesterXL for posting about isLivePreview and LivePreview a 
topic which sorely needs more documentation. It's great if it 'just works.'

I have an app that includes a component with a xml socket connection.  I find 
that when I replace the component or when I open my FLA, the component is 
initialized and tries to make the socket connection.  I thought I could use 
isLivePreview to avoid the socket block.  But, I find that isLivePreview is 
undefined initially and the socket gets established.  To fix this problem I 
found that I could add a short delay before making the socket connection and in 
that period isLivePreview is defined (true).

John laPlante
Carnegie Mellon University
[EMAIL PROTECTED]

Message: 15
Date: Fri, 25 Mar 2005 13:23:01 -0500
From: "JesterXL" <[EMAIL PROTECTED]>
Subject: Re: [Flashcoders] isLivePreview
To: "Flashcoders mailing list" <[email protected]>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain;       charset="iso-8859-1"

I haven't seen this documented, nor have I looked; this is merely what I've surmised from digging in the framework. If you look at the mx.controls.Label, and others, you'll see they'll size differently whether they are running in LivePreview or not.

To define, LivePreview is when you have a component on the stage in Flash, at authortime, and you have the LivePreview option on in the IDE. What this does is instead of showing a the innards of your component, it shows a SWF representation of it intead. In Flash MX, you'd typically just create a seperate FLA, drop your component in, and add some simple Stage.onResize code to have your component scale when the stage changed. This changing of the stage size will then be triggered when someone resizes your component on the stage.

2 things in Flash MX 2004 made LivePreview better. First, they made creation automatic if you created an SWC. If you open an SWC in WinZIP, you'll see the SWF in there that Flash created for you; it uses the #include "mm_livepreview.as" file when making that SWF. Basically, it's your component + that include file, automatically created for you.

That way, when someone installs your SWC, Flash already has a LivePreview created for it if someone so chooses to use it at Design Time (authortime).

Now, knowing that your code will be used in 2 places, in a Flash app and in a SWF running in a little box that represents your component on the stage, you can have it size & behave differently. You do this by checking the value of _global.isLivePreview. If it's true, it's running in a LivePreview SWF (SWF inside a movie clip in the IDE at design time). If not, your running in a SWF elsewhere.

Now, #iniclip is different. The same "IDE magic" that automatically creates a SWF and includes the mm_livepreview.as file is the same magic that deals with #initclip. #initclip merely tells Flash, "make this component initialize at this time, and this one after, and this one before, etc. It does this when you compile. Flash MX, and Flash MX 2004 do not support compile time directives, or "code that runs when you compile your SWF... save 2:

#include and #initclip

There isn't much allowed with #include. A string that is a filepath to an AS file, and that's it. No variables, no dynamic #including, nothing; just a string, period, end of story.

Same goes for #initclip... except it has to have a number, not a string (optionally; if you put nothing, Flash'll just initialize in the order it sees fit).

So, using ActionScript to see if your running LivePreview to determine whether or not an #initclip is appropriate will not work; by the time your code is ready to run, the SWF was already made, and the #initclip was already implemented, there is no getting around it.



_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to