I have a .fla that gets opened up, a few actionscript variables (a url, title etc.) are changed, and published. This happens a lot, and it's the same variables. I would just keep the .swf file with an XML file, but it being uploaded to a third-party platform, so all of the information needs to be contained in the .swf file. There is no way to add the variable information to the third-party site.
I want to know if there's a way to take the new variable information from an xml file or something at publish time (like a script?) without having to open up the Flash IDE. To be able to do a bunch of these at once would also be great.
Any help/links/leads would be appreciated. Google did not help me. Is this even possible?
Without opening the Flash IDE would require loading external resources or a build script using ANT or simply with the mxmlc compiler, something to the effect of:
mxmlc -o output.swf -source-path="src/" -library-path+=library.swc.
Flex compilers
About mxmlc
As you indicate embedding XML at compile time, you could either embed the XML using the [Embed] metadata tag or paste your XML in a class.
Embed XML
package
{
public class XmlData
{
[Embed(source = "data.xml", mimeType = "application/octet-stream")]
public static const Xml:Class;
}
}
To use the XML, instantiate the xml as:
var xml:XML = new XML( new XmlData.Xml );
XML variable
Otherwise, you can simply paste your xml in a class like so:
package
{
public class XmlData
{
public static const xml:XML =
<root>
<element />
<element attribute="value">data</element>
</root>;
}
}
Although you must compile your SWF, this approach is easy because you can simply paste your XML document to the class.
This would be referenced as normal with e4x and no asynchronous load required.
var data:String = XmlData.xml.element.#attribute;
Related
In my windows store app using the Visual Studio 2012 designer I want to be able to load some model objects for the designer. I've done this plenty of times before where I supply a xaml file using the ms-appx:/// uri without error. However, for this project I need to be able to instantiate a class and have it convert raw xml of a different format into my model objects.
I'm using the following xaml to instantiate my class for the designer:
d:DataContext="{Binding Source={d:DesignInstance Type=model:Walkthroughs, IsDesignTimeCreatable=True}}"
In my Walkthroughs class had code that did this initially:
public Walkthroughs()
{
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
AppDataLoader.LoadWalkthroughs(this, XDocument.Load("ms-appx:///SampleData/walkthroughs.xml"));
}
I first ran into an issue where the XDocument.Load did not understand the ms-appx:/// uri so I modified my code to something very simplistic:
AppDataLoader.LoadWalkthroughs(this, XDocument.Load(#"C:\walkthroughs.xml"));
Now I get access to path '' is denied.
I've tried several directories as well to no avail. I'm even running Visual Studio as an Administrator. If I remove the prefix altogether I get the following error:
Could not find file 'C:\Users\{me}\AppData\Local\Microsoft\VisualStudio\11.0\Designer\ShadowCache\omxyijbu.m4y\yofsmg1x.avh\walkthroughs.xml'.
Has anyone been able to load files from the file system when the designer instantiates objects?
Thanks,
-jeff
XDocument.Load(string uri) seems to have problems with loading Project resources from ms-appx:/
Regarding your second approach: Direct access to "C:" is not permitted. Ther is only a handful of special folders that you can access. Check out my workaround for this (my xml file is within the Assets folder of my project:
var storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
storageFolder = await storageFolder.GetFolderAsync("Assets");
var xmlFile = await storageFolder.GetFileAsync("data.xml");
var stream = await xmlFile.OpenReadAsync();
var rdr = new StreamReader(stream.AsStream(), System.Text.Encoding.GetEncoding("ISO-8859-1")); //needed if you have "ä,ß..." in your xml file
var doc = XDocument.Load(rdr);
I recently found Mike Chambers' as3corelib when looking for ways to render the stage to a file. Works great in my ActionScript 3.0 project in Flash Professional (CS6 if it matters).
I decided to look at some of Mike's utility classes, notably the date related ones. However, his DateUtil class imports mx.formatters.DateBase, and when I attempt to use some of the methods, I'm getting lots (and lots) of "Access of undefined property DateBase."
I'm assuming that's because some reference to the Flex SDK is missing or wrong. I've added $(FlexSDK)/frameworks/libs/flex.swc to my project's Library path, but that's not helping.
I've used Flash for years, but this is my first truly code-centric project, and still learning through the school of hard knocks. No idea what's going wrong here. Ideas?
Example from as3corelib
package com.adobe.utils
{
import mx.formatters.DateBase;
/**
* Class that contains static utility methods for manipulating and working
* with Dates.
*/
public class DateUtil
{
/**
* Returns a date string formatted according to RFC822.
*/
public static function toRFC822(d:Date):String
{
var date:Number = d.getUTCDate();
var hours:Number = d.getUTCHours();
var minutes:Number = d.getUTCMinutes();
var seconds:Number = d.getUTCSeconds();
var sb:String = new String();
sb += DateBase.dayNamesShort[d.getUTCDay()];
sb += ", ";
...
The line:
sb += DateBase.dayNamesShort[d.getUTCDay()];
...generates the mentioned error, as does any other DateBase reference in the class. Again, this code is directly from the latest as3corelib, located on GitHub: https://github.com/mikechambers/as3corelib
Don't know whether you got this one licked or not, but I hit the same thing. Love the library, hate the error messages.
I downloaded the Flex SDK from here:
Adobe Flex SDK Download
Then, I unzipped that into a temporary folder.
Then, since I didn't want the whole flex framework lurking about, I created a ./lib directory inside the directory where the .fla file lives. I then moved these swcs from here (Inside the unzipped file structure):
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/framework.swc ./lib
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/core.swc ./lib
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/mx/mx.swc ./lib
Not sure why all three were required, but it stopped the compiler complaining (and got the date conversions working).
You need to add them to the .fla's library list as well (under ActionScript Settings); but I'm betting you already knew that.
Perhaps useful, perhaps not.
I want to use the as3 File() method to import an xml into a file.
The file is inside my project in the package resources/xml/baseXml.xml
Now the File() method has several properties like:
applicationDirectory, applicationStorageDirectory, desktopDirectory, documentsDirectory
But none of them points me in the right direction. So how should i do this? To get the xml file inside the package?
I have tried to embed the file to be then i have a Class and not a File.
Do you NEED to use File()? What if you were to just get the xml file with httpService?
Try:
<s:HTTPService url="resources/xml/baseXml.xml" result="yourResultHandlerToParseTheXML(event)"/>
Or you could just do:
<fx:XML source="resources/xml/baseXml.xml"/>
And parse off of that.
(Both would be located inside your tags.
Unless you need an ActionScript only solution in which case the below SHOULD work:
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.load("resources/xml/baseXml.xml");
My requirement is to instantiate an object using new ActiveX() in html.
I have created a COM component SimpleActiveX using ATL. I have created the dll SimpleActiveX.dll for the same. In order to instantiate this component in html file I need to register the dll. So I registered the dll using the command regsvr32 %Path of dll%.
After doing so I am trying to create and instance of the component in html file as follows,
var req;
req = new ActiveX("SimpleActiveX.Hello"); //Assume Hello as a class.
req.Hi(); //Assume that Hi() is a member function of Hello.
By doing so I am unable to create the ActiveX object.
Html doesnt give any error too. I dont know whether I am doing anything wrong or am I missing anything.
Could anyone please tell me the proper steps to perform above operations.
How do I need to create the dll (Here in this case I have just build the ATL project in Visual Studio to generate the dll)?
What else do I need to do with the dll in case if I need to create an ActiveX object in html?
I had come across something called as <object> </object> tag in html where we mention the classid and attributes. I dont know whether I need to mention this in my html file or not.
Thanks for your help in advance.
To instantiate an ActiveX object in JavaScript, assuming the dll is correctly registered, you just have to use:
var req = new ActiveXObject("SimpleActiveX.Hello");
Unfortunately I don't know how to register a dll using Visual Studio.
Regarding the tag, it is used when you want to embed the object directly in your HTML code, so that it will be instantiated when the document loads, instead of using JavaScript.
For example:
<object id="myObject" classid="CLSID:2D360200-FFF5-11D1-8D03-00A0C959BC0A"></object>
Then you can access the COM object with
var myObject = document.getElementById("myObject").object
I just started learning ActionScript, so maybe this is obvious. I'm loading in .txt files to generate content for my Flash application. However, I can't seem to find a way to package the .txt files with the .swf when I publish my application. I'd like to be able to run the .swf from anywhere without it depending on the files. Is there a solution for this?
Thanks!
this is an excellent post by Emanuele Feronato:
how-to-embed-a-text-file-in-flash
Basically you use the embed syntax to embed the file as a ByteArray. The key method here is to call the toString() method on the ByteArray to convert to a string.
Hope this helps
Try loading .as files, with variables defined inside them. They're, technically, still text files and still easy to edit, but they get automatically encapsulated in the .swf.
In your main stage, you just add include 'included.as';. In your included.as file, you just define whatever variables you want, for example:
var someData:Array = new Array();
someData.push('This is some string');
someData.push('This is some other string');
After you include the as, you can call whatever variable you defined. And when you export, the .as file is embedded into the .swf.
Even better then just embedding a .txt with your flash, if you're more versed with programming I would suggest you to create a static class to store the values of your application.
Just like:
class StaticData {
static public var siteTitle:String = "My site name";
static public var homeMessage:String = "Lorem Ipsum dolor sit amet...";
static public var welcomeMessage:String = "Hello World";
static public var siteWidth:Number = 1024;
static public var siteHeight:Number = 780;
}
This is a safe and realiable way to store static values using a simple class structure, to use a value from the class, you just need to call inside your flash:
my_textfield.text = StaticData.siteTitle;
my_shape.width = StaticData.siteWidth;