I have this project at school, where I am supposed to make an image recognizer not importing any photos into Flash. Here's the error I´m getting:
Error #2044: Unhandled ioError:. text=Error #2035: URL Not Found. URL: file
Anyway, this is the file (p.s. it's Norwegian. And yeah, I'm a noob, I know.)
http://www.megafileupload.com/en/file/507257/recognizer-fla.html
I have tried similar methods, but nothing seems to work - again, I'm a noob. I have only been coding for two months.
not importing any photos into Flash
It's easy to load external image. You will need Loader class, image will be represented as instance of the Bitmap class. If you get IOError, I assume your url isn't correct.
Example:
var loader: Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("http://www.billboard.com/files/styles/promo_650/public/stylus/1235529-taylor-swift-woman-of-the-year-617-409.jpg"));
function onComplete(e:Event):void{
var bitmap: Bitmap = LoaderInfo(e.currentTarget).content as Bitmap;
addChild(bitmap);
//Do whatever you want with the image
}
Related
I can successfully load a 3D object from, for example, an FBX File, load and play it's animations. The problem is that, after doing what i gotta do with it, i need to save the changes. To do that, I'm saving the object and the object animation clip to a JSON. I can, now, load the 3D Object in the scene, but no animations will play(it'll stand on T pose), but trying to load the saved clip on the object loaded from FBX will play the animation without a problem.
After reading the resulting JSON from the 3D Object, a lot of data seems to be missing, that's why trying to play animations does nothing.
How can i save the loaded FBX model to a .json and keep the important data? I remember seeing some post about putting some flags on the toJSON method, but couldn't find anything similar again.
Edit:
Using GLTF seems to solve this problem, but three.js GLTFLoader isn't loading any kind of .gltf object and i don't know why, for all of the objects i've tried using (used objects from threejs.org GLTFExporter examples) i'm getting the same error:
TypeError: Cannot read property 'geometry' of undefined
at GLTFLoader.js:2572
That's how i'm trying to load it:
loader_helper.gltf_loader.load("./src/data/scene.gltf", function ( gltf ) {
console.log(gltf); // This is enough to get the error, altough i've tried
// mimicking the FBX import, but getting the same errors
});
Edit: Using https://gltf-viewer.donmccurdy.com/ to view the object, the object i exported was completely bugged ( https://imgur.com/a/yLimuWp ) and i didn't notice, but i tested the bugged object three times, so i thought the problem was in the loader, it is seems to be loading fine using a non-bugged object. Although the export is bugged, the object skinned mesh is loading without issues and only the mesh is being loaded with, wel.. you saw it. https://imgur.com/a/evGmnOG
That's how i'm exporting the scene:
// this is a button.onclick function
var exporter = new THREE.GLTFExporter();
exporter.parse( that.scene, function(gltf){
var stringfied = JSON.stringify(gltf, null, 3);
require("fs").writeFile( "./src/data/scene.gltf", stringfied, 'utf8', function(err) {
console.log(err); // saving it to file with nodejs file system
});
console.log(gltf);
} );
I've been trying for two days to find an alternative to loading an image into my current project. I am using Adobe Flash Professional CS6 as my IDE and Animation program. I would like to be able to display an image in my application. What I am trying to do is have the image display onto the screen, the user enters the PLU associated with the image, and if the PLU is right then they receive a point. I have everything else already to go, but I just can't find an efficient way to deal with loading the image.
Right now I'm using this to accomplish getting my image on the display:
var myDisp:Layer0 = new Layer0();
var bmp:Bitmap = new Bitmap(myDisp);
spDispBox.addChild(bmp);
The above code works just find, but the limitation I can't get around is that I'm going to have to import each image into the library and then consecutively code each part in. I wanted to stick to OOP and streamline this process, I just don't know where I should turn to in order to accomplish my project goal. I'm more than happy to give more information. Thanks in advance, everyone.
July, 26, 2014 - Update: I agree, now, that XML is the way to go. I'm just having a hard time getting the grasp of loading an external XML file. I'm following along, but still not quite getting the idea. I understand about creating a new XML data object, Loader, and URLRequest. It's just loading the picture. I've been able to get output by using trace in the function to see that the XML is loaded, but when I go to add the XML data object to the stage I'm getting a null object reference.
I'm going to try a few more things, I just wanted to update the situation. Thanks again everyone.
it seems like these images are in your FLA library. To simplify your code you can make a singleton class which you can name ImageFactory (factory design pattern) and call that when needing an image which will return a Sprite (lighter than a MovieClip)
spDispBox.addChild( ImageFactory.getImageA() ); // returns a Sprite with your image
and in your ImageFactory
public function getImageA():DisplayObject {
var image:Layer0 = new Layer0(); // image from the FLA library
var holder:Sprite = new Sprite();
holder.addChild( new Bitmap( image ) );
return holder;
}
also recommend using a more descriptive name than Layer0
I wrote a little tool with node-webkit. One reason I chose node-webkit is the fact that it is easy to distribute your app to all major plattforms.
Something I would love to do now, is to resize a bunch of images located on the file storage.
I found plenty of packages which do this via ImageMagick. This would require the user to have ImageMagick installed, which is bad...
Using a webservice is no option. There can easily be around 600 images.
If there is no solution, I will only run that task IF imagemagick is installed.
You could use the canvas tag to resize your image.
Load the image in a canvas with the new size:
...
var tempCanvas = document.createElement('canvas');
tempCanvas.width = newWidth;
tempCanvas.height = newHeight;
var ctx = tempCanvas.getContext('2d');
var img = new Image();
img.src = imageSrc;
img.onload = function () {
ctx.drawImage(this, 0, 0);
};
Get resized image back from canvas:
...
var image = canvas.toDataURL('image/png');
image = image.replace('data:image/png;base64,', '');
var buffer = new Buffer(image, 'base64');
fs.writeFile('filename.png', buffer, function (error) {
if (error) {
// TODO handle error
}
});
...
In this example the resulting image will be a png. You can use as result type whatever node-webkit supports. If you have different image types as input and want to output in the same type you need to add some code that sets the correct mime type to canvas.toDataURL.
I am developing an image processing module without any runtime dependencies; which means your users don't need to have imagemagick installed. It's still at early stages, but already usable.
Part of the module is written in C++, so you'll have to make sure to npm install the module on each platform you package your app (better than telling your users to pre-install imagemagick, imho). node-webkit apps are distributed per-platform anyway, so it shouldn't be a problem. Note, though, that I haven't yet tested it with node-webkit,
With this module, resizing an image is as simple as:
image.batch().resize(200, 200).writeFile('output.jpg',function(err){
// done
});
More info at the module's Github repo.
This issue has been following me around for almost a year now, and I want to kill it, for my sake and for the sake of all.
I'm working on some banner ads that need to load in images from a client's site for display. When I tried to do this using AS2, I found out that AS2 doesn't let you do that. It's a bug in the language. There are workarounds for images on the local server, but images loaded from are not allowed to share their BitmapData, so those workarounds don't work. I ended up capitulating after about two months of banging my head against the desk and cursing Macromedia.
Now we are talking about moving to AS3 (finally) and I'm really excited. Or, I was really excited until I started doing some tests for image quality and found that there is very little change in image quality happening here. It's a repeat of my trials with AS2: everything loads perfectly in the IDE, I get all excited, I move the swfs over to the test server to run them online, and POOF - jaggies. Jaggies everywhere.
I've read a number of solutions online, none of which work. They include:
Setting target.content.smoothing to "true". Works great in the IDE. All improvements disappear in the browser.
Setting target.scaleX = target.scaleY to 1.01. It just breaks the swf.
Adding "new LoaderContext(true)" to my parameters for the load command. Does nothing.
Setting target.content.pixelSnapping to "always". Looks perfect in the IDE, not in the browser.
Setting a crossdomain.xml file. The images are showing up - they're being loaded, even if jaggedly, so there must be a functioning crossdomain file on the client's server, right?
So now I'm just stuck, and brokenhearted. Could anyone offer insight on my code, and why it might not be rendering as beautifully as it should be? Here is the client-safe version of the quick demo I am making (only the image URL has been deleted, everything else is as it is now):
import flash.events.Event;
function completeHandler(e:Event) {
e.target.content.pixelSnapping = "always";
e.target.content.smoothing = true;
}
var imgurl:String = "CLIENT'S IMAGE URL HERE";
var imageLoader01:Loader = new Loader();
var image01:URLRequest = new URLRequest(imgurl);
imageLoader01.load(image01);
imageLoader01.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
addChild(imageLoader01);
imageLoader01.x = 2;
imageLoader01.y = 0;
imageLoader01.scaleX = imageLoader01.scaleY = .6;
var imageLoader02:Loader = new Loader();
var image02:URLRequest = new URLRequest(imgurl);
imageLoader02.load(image02);
imageLoader02.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
addChild(imageLoader02);
imageLoader02.x = 100;
imageLoader02.y = 80;
imageLoader02.scaleX = imageLoader02.scaleY = .308;
var imageLoader03:Loader = new Loader();
var image03:URLRequest = new URLRequest(imgurl);
imageLoader03.load(image03);
imageLoader03.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
addChild(imageLoader03);
imageLoader03.x = 200;
imageLoader03.y = 180;
imageLoader03.scaleX = imageLoader03.scaleY = .152;
var bannerLegend:legend = new legend();
addChild(bannerLegend);
Thank you very much in advance. Any help will be sorely appreciated.
Update: Here is the HTML embed code:
<div id="swf_mr_sc_wt_si"></div>
<script type="text/javascript">
<!--
var swfurl = "http://DOMAIN_WITHELD_SORRY/static/AS3.swf?m=DEFAULT&t=" + (new Date().getTime());
swfobject.embedSWF(swfurl, "swf_mr_sc_wt_si", 300, 250, "8.0.0", "");
// -->
</script>
<p>
Hope this helps.
Further Update: We are not listed in the crossdomain.xml file. But we can still load the jagged images. And those images, when loaded into the same swf run in the IDE, are smooth. I think I'm missing understanding of some kind of apocryphal knowledge here, because everything I read points to me being able to do this. This is VERY confusing.
It's because the image you're loading is located on another domain, and that domain's crossdomain.xml does not contain the domain the .swf is residing on, basically giving the .swf "permission" to access the image's pixel data (Yes, just enabling smoothing on an image loaded from another domain requires the same security as when reading the pixel data using BitmapData.draw(), which is a bit curious). When running in local security sandbox the restrictions are more lax, that's why it works running from the IDE.
Even if your domain were among the approved domains in the crossdomain.xml you might need to tell the Flash Player to check the policy file by sending in new LoaderContext(true) as a second argument to Loader.load() when loading the image.
Edit: I originally thought using loadBytes() would be a workaround, but it turns out it's not. I have removed that example code
I'm trying to smooth an scaled image loaded from another website. The image is not animated.
It works well if I use a local image. but it seems not work with images loaded from remote server.
Here is the snippet:
...
//_loader.load(new URLRequest(http://img.example.com/remote.jpg));
_loader.load(new URLRequest("../assets/local.jpg"));
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
...
protected function completeHandler(event:Event):void
{
var image:Bitmap = Bitmap(event.target.content);
image.smoothing = true;
image.pixelSnapping = "never";
}
As tested, when I load local.jpg, it works perfect. But when I load remote.jpg from the server, the smoothing param didn't work.
Anyone knows why?
I searched everywhere, but no one has the same problem. I'm not using Flash Professional, it's a pure ActionScript Project built in Flash Builder. And the image is not animating. So wired...
Because you are pulling an image from a remote server you need to set a cross domain policy xml file on the web server where the image is held.
Without this you can't alter bitmaps at a sub pixel level.
Example of:
http://www.senocular.com/pub/adobe/crossdomain/policyfiles.html
More details
http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.edu.html
I searched day by day, and finally find the answer:
_loader.load( new URLRequest("http:…." , new LoaderContext(true));
The most important is the second param of load() method, it's a LoaderContext. Reference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#load()
Although I set the crossdomain file in the server, without the "new LoaderContext(true)", it won't read the crossdomain file. That's why it doesn't work at first.
If you have the same problem, hope it's helpful to you!